I have been trying to find a way to use macro define strings as their values during run time. My test scenario is like this
In user-defined file 'data.txt'
Reg1 0x12345678
In test.c
extern write(uint64_t addr, uint32_t value);
main(){
FILE * reg_data;
char reg_name[256];
uint32_t value;
reg_data = fopen("data.txt", "r");
if(reg_data == NULL){
print_log("Cannot open file data.txt\n");
exit(-1);
}
while(fscanf(reg_data, "%s %x \n", reg_name, value) != EOF){
write((uint64_t)reg_name, value);
}
}
In another included file 'head.h'
#define reg1 0x400000000
So I want my write call to translate to write(0x400000000, 0x12345678)
However since these #define are replaced at compile time it is not taking effect. Also since I have a typecast on string it passes compilation and elaboration substituting int equivalent of the string.
Is there any way to accomplish this? The main requirement is user generated file has define macro strings and not actual address values.
main()signature is wrong, it can beint main(), but not justmain()without any return type.strtol()and pass base16to it. And also,write()is a standard function and it takes 2int'sReg1doesn't equalreg1.