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

  • Home
  • SEARCH
  • 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 8195477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:09:07+00:00 2026-06-07T05:09:07+00:00

Yes, I know dynamic variables aren’t possible in c++. What I’m looking for is

  • 0

Yes, I know dynamic variables aren’t possible in c++. What I’m looking for is a workaround.

The idea is basically this. I’ve got a bunch of mathematical models together. They all have the exact same form, except for

  1. the mathematical definition of a few functions
  2. the needed constants: what they’re called, their number, and their values.

The values of the constants may change between experiments, but everything else is a property of the material model itself. The constant parameters of the model are given in the input file in the form

variable_A=2.0

The material models (including all functions) were previously made through generated code, generated from abstract mathematical expressions through Maple, with a nice GUI environment to boot. This is now sadly broken, for multiple reasons. As a result of some other work, the models are now all the exact same in code, except for where they differ in their formal description. Instead of having a whole separate program to generate this code (which is currently broken and what we used to have), I’m looking for a simpler alternative, since now I only need roughly 20 lines throughout a given file to differentiate one material from another. However, the users who would implement these models aren’t expected to have any knowledge of c++. So while I could simply ask them to go through the file and change things in various places, I was looking for something a little more user-friendly: so the user can just change a few lines in one place and define their model that way, without having to look through the rest of the code.

The functions to be defined by the user look like this.

double myfunction(double arg1, double arg2, vector arg3 ) \\just an example
{
    ...
    ...
    double a=database.find_constant("a_const");
    double b=database.find_constant("b_const");
    return sqrt(a*3+pow(b,2)-a/b)+...; \\still example pseudocode
}

The top ellipses are fairly ugly (not bad code, just syntax heavy and irrelevant), and so I don’t want the end user to have to deal with them. My problem can probably be better described through examples:

My original plan was to use macros (yes, I know, the horror) at the top, so that this could become something like

 #define A database.find_constant("a_const")
 #define FUNCTION pow(A-2,3)   
 ...
double myfunction(...)
{
    ...
    return FUNCTION;
}

but then I found out that you can’t nest macros. Which in retrospect is obvious, but I digress. Then I realized that I could just change the #define A statement to make A a global variable. Then i hit myself for even considering global variables. Basically, all my attempts to stick this all in one place where the user doesn’t need much knowledge of c++ are ridiculous and/or horribly insecure.

Normally i hate asking such open ended questions, but I really don’t want to give myself headaches. I’ll only be working on this project for a short time, so designing a UI of some form and/or generating the code isn’t practical. I’m going for ‘proof of concept’ at the moment.

Is there a better way to do this than having them go through the model and change the needed lines in the functions directly?

EDIT: I didn’t write this whole project, nor was it originally intended to work in this way. The original tool we had for producing these files used Maple’s code generation, where the functions and variables were entered as Maple syntax in a nice GUI. Unfortunately the GUI doesn’t seem to work (consistently) anymore, and the code Maple returned stopped producing the right results once we switched versions: we’re not sure what the problem is exactly, and we’re just exploring other avenues right now. The new files are also much more similar than the previous ones (as a result of other work), which is part of the motivation for a new technique. I was hoping that I could get around code generation if I only needed a few lines to work together in a simple way. This isn’t a “fix it for me!” question, I’d just like to get a handle on what those other options might be. Yes I know it’s not a good situation to begin with, and if this was planned from the start it would not be done this way. But this setup will probably be temporary, and as I said is more of a proof of concept than anything else.

Hopefully the question is clearer now. My issue is specifically with grouping everything in one place in a simple to use manner. Thank you for your patience.

  • 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-06-07T05:09:09+00:00Added an answer on June 7, 2026 at 5:09 am

    Something you can try that ‘acts’ like macros but isn’t, is to encapsulate the various function groups in anonymous structs:

    struct
    {
        double find_constant(const char* s) { do-stuff...; }
        double calc_value(int a, int b) { do-stuff...; }
        ...
    } GeneralStuff;
    

    Use a macro to access the functions in this struct:

    #define DoStuff GeneralStuff

    and in your code access it:

    ...
    DoStuff.find_constant("a_const");
    ...
    

    If a user needs to change the code, he makes a copy of the struct, apply the changes, and
    redefines the macro:

    struct
    {
        ...changed code...
    } MyStuff;
    
    #define DoStuff MyStuff
    

    These would be the only changes needed, if I understand your question correctly.

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

Sidebar

Related Questions

I got this crazy idea that I don't know is possible or not... what
Yes I know there has been similar posts to this however after looking through
First, yes I know about this question , but I'm looking for a bit
Yes I know, this title isn't really helpfull but this is the exact problem.
Yes I know I can do this with stored procedures. I'm wondering if it's
Yes I know, this question has been asked MANY times but after reading all
Yes i know about ( This post ) , if you search you will
Yes, I know that downcast using dynamic_cast can't compile if the Base is not
Yes I know that it shouldn't be abused and that C# is primariy used
(Yes I know I can call Java code from Scala; but that is pointless;

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.