Is there any means to change value of a macro depending on some execution during run time ?
e.g #define VALUE A
now I want this A to get different values during code execution ,
say in main ()
A=x+y;
A can be different values based on x or y, how can I assign Value of this variable to macro VALUE ?
Re: how to change avalue of macro during execution?
AFAIK macros are compile time, not run time. So no, that's not possible. But you can obviously use a function or variable to take care of all your runtime needs.
Re: how to change avalue of macro during execution?
It will work if A is a variable. "VALUE" will be replaced with "A" early at compile time, so all references to "VALUE" will use the number stored in variable A.
Normally a macro is used to set a constant value like this:
#define VALUE 32
A macro in C is just a text substitution done at compile time, so a fixed number is not necessary.
A variable name will work:
Code C - [expand]
1
2
3
4
5
6
7
8
#define VALUE Aint A;
....
A= x + y;if(VALUE >123){printf("Above 123\n");}
....
The compiled code will look like this:
Code C - [expand]
1
2
3
4
5
6
7
int A;
...
A= x + y;if(A >123){printf("Above 123\n");}
....
As shown, the variable "A" can be declared after the #define since it is just a text string in the #define.
"A" must be declared before the macro VALUE is used.
I wonder how you guys learn HDL and also C togethor and yet live without confusion. I have not learnt C myself yet much, but still just finding it tough than learning HDL,