Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:37:02+00:00 2026-05-25T17:37:02+00:00

This is the function that checks the name of the function entered by the

  • 0

This is the function that checks the name of the function entered by the user into the interpreter/parser I am making, compares it with the array of functions, and executes the corresponding C++ function. It works fine as long as the user enters a correct function name, but the interpreter ends with some unexplained runtime error if there is no function of the name the user entered, even though I programmed it to print “Undefined Function” and then carry on the parse loop:

void parser::eval_cmd(std::string& exp, pro::command fset[])
{
    expr = exp;
    exp_ptr = (char*) expr.c_str();

    bool found = false;

    for (int i = 0; i < (int)sizeof(fset); i++)
    {
        if (fset[i].check(expr))
        {
            found = true;
            exp_ptr = (char*)expr.c_str() + (fset[i].name.size() - 1);
            if (fset[i].cmd)
                fset[i].cmd(eval_args());
            break;
        }

    }

    if (!found) err::show(err::UNDEFINED);
}

What exactly am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:37:02+00:00Added an answer on May 25, 2026 at 5:37 pm

    What you are doing wrong is (int)sizeof(fset). That gives you the size of a pointer, in bytes, not the number of elements in the passed-in fset array.

    You need some other way of determining how many elements are in the array, perhaps by passing in another arg, by using an std:: container instead of an array, or by NULL-terminating the array.

    For example, changing your function definition slightly:

    void parser::eval_cmd(std::string& exp, const std::vector<pro::command>& fset)
    {
        ...
    
        for (int i = 0; i < fset.size(); i++)
        {
            ... 
    

    The remainder of the code is unchanged.


    EDIT: My best advice is to use std::map<string, pro::command> and allow map to manage the lookup algorithm, or std::vector<pro::comand> and use the above algorithm unchanged. You can measure the memory performance, but I expect that the only overhead of vector over array is the overhead of a newed array over a static array.

    If you do reach the conclusion not to use standard containers, here is my 2nd-best advice:

    void parser::eval_cmd(std::string& exp, pro::command fset[], size_t count)
    {
        ...
    
        for (int i = 0; i < count; i++)
        {
    

    Presumably the caller knows (or can determine) the number of elements in the fset array. (See Can this macro be converted to a function? for help with that.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code snippet inside a function that checks if an object exists
I have this function that prints the name of all the files in a
Inside a function I have created, I have this loop that checks if the
I have a function that checks if a cookie (by name) exists or not:
I'm trying to make a function that checks if the user is logged in.
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000" .
So I have this function that forks N number of child processes. However it
I have this function that converts all special chars to uppercase: function uc_latin1($str) {
I need to create a function that uses a loop. This function will open

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.