Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the value of a c constant

Tags:

c++

c

I have a .h file in which hundreds of constants are defined as macros:

#define C_CONST_NAME Value

What I need is a function that can dynamically get the value of one of these constants.

needed function header :

int getConstValue(char * constName);

Is that even possible in the C langage?

---- EDIT

Thanks for the help, That was quick :)

as i was thinking there is no miracle solution for my needs.

In fact the header file i use is generated by "SCADE : http://www.esterel-technologies.com/products/scade-suite/"

On of the solution i got from @Chris is to use some python to generate c code that does the work.

Now its to me to make some optimizations in order to find the constant name. I have more than 5000 constants O(500^2)

i'm also looking at the "X-Macros" The first time i hear of that, home it works in C because i'm not allowed to use c++.

Thanks

like image 383
azalsup Avatar asked Jul 18 '11 15:07

azalsup


People also ask

What is the value of AC?

Hint: Mean value of an alternating current is the total charge flown for one complete cycle divided by the time taken to complete the cycle i.e. time period T. The value of an alternating current changes with time. Also, its direction changes after every half cycle. Hence, for a full cycle, the average value is zero.

What is rms value for AC?

Root mean square or R.M.S. value of Alternating voltage is defined as that value of steady Potential Difference, which would generate the same amount of heat in a given resistance is given time, as is done by A.C. voltage , when maintained across the same resistance for the same time.

How is average value of AC calculated?

Derivation – The average value of AC can be obtained by integrating the instantaneous values of current or voltage over the half cycle i.e. area of the curve over half cycle and dividing the result by base length of half cycle.

Is rms value AC or DC?

RMS or root mean square current/voltage of the alternating current/voltage represents the d.c. current/voltage that dissipates the same amount of power as the average power dissipated by the alternating current/voltage.


1 Answers

C can't do this for you. You will need to store them in a different structure, or use a preprocessor to build the hundreds of if statements you would need. Something like Cogflect could help.

like image 59
Ned Batchelder Avatar answered Oct 14 '22 04:10

Ned Batchelder