CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009

    Exclamation Evaluating code passed by argument?

    In a small DLL I'm working on, I need a way for the user to enter a functional definition, which is then passed to my function as an argument (PCHAR), and have this evaluated.

    For example, if my function is defined thus:

    double eval(PCHAR func,PCHAR vari,double val) { }

    And the user calls it thus:


    It will return 20, as 3x+5=20 when x=5.

    This is similar to Javascript's eval() function, but as C++ is nothing like Javascript, I doubt it'll be so easy.

    Is there any way to do this? I need the user to be able to pass their custom functions to the DLL for evaluation.

    If it matters, due to compatibility constraints, only PCHARs and doubles may be passed as arguments or returned, though anything goes within a function.


  2. #2
    Join Date
    May 2007

    Re: Evaluating code passed by argument?

    It can be done, but you will need to write code to interpret the data (I would look at using stringstream to do the coversions from string to double.

  3. #3
    Join Date
    Oct 2006

    Re: Evaluating code passed by argument?

    You can have a look at this example for math parser.
    It's not C++, but you can easily rewrite it in C++.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.