Is there a way to determine the "final value" of a expanded C macro by inspecting the compiled object or by running some form of gcc -E on the .c or .h file?
test.h
#define AAA 1
#define BBB 10
#define CCC (AAA+BBB)
test.c
#include <stdio.h>
#include "test.h"
int main(){
printf("%d\n", CCC);
return 0;
}
Thus is there someway to get the expanded value either:
#define CCC 11
or
#define CCC (1+10)
If compiled with
gcc -dM -E test.c | grep CCC
or
gcc -dD -E test.c | grep CCC
outputs
#define CCC (AAA+BBB)
which requires me to still know what AAA
and BBB
are.
Compiled with:
gcc -E test.c
Gives (skipping the boilerplate):
# 4 "test.c"
int main(){
printf("%d\n", (1+10));
return 0;
}
While its expanded CCC
I've now lost the mapping back to CCC
.
Edit: As it was unclear, what i'd like is someway to determine what CCC is (either 11 or 1+10 (as the gcc -E example showed it only inserted (1+10) not 11), preferably without altering the code itself. Printf was a bad idea to use in the MRE, what i actually had in mind was code like:
struct my_struct {
int my_array[CCC]
... other stuff ...
}
The question is how big is my_array, so i can make a struct in another language (python via ctypes) and know how much space i need. I know for structs i can use pahole but was hoping to do this with only gcc and in the more general case (say a global array not in a struct).