How to get the address of a variable stated in C Macro? -


i new c , trying macro statements. have line this:

#define write_data(src, type, value ) (write_implement(src, sizeof(type), &(value))) 

and in later function, use memcpy copy value in memory zone. this:

void write_implement (void* src, int size_of_type, void* value) {     //whatever, making destination address source address     void* dest = src + 4096;     memcpy(dest, value, size_of_type); } 

the value being passed in can of kind of data. that's why using void* point , memcpy copy number of size of bytes.

but doesn't work of course :)

this how call function:

write_data(addr, int, i*3); // whatever integer variable 

gcc gives me this:

error: lvalue required unary ‘&’ operand

does have idea how find address of variable being passed in macro in order allow me make use of address copying?

the later part of macro can changed (the "write_implement" , parameters not "write_data" parameters). , implementation part free change.

if compiler supports c99 compound literals, can this:

#define write_data(src, type, value) write_implement(src, sizeof(type), &(type){ value }) 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -