This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Using define inside a #define


I want to streamline some code.  If I use a macro like

#define CRTL1 (*(unsigned int *)0x100000)

I can use CRTL1 as if it were a register inside my code.  For example

CRTL1 = 10;

or 

printf( "The value is %d\n", CRTL1 );

and it access the value of the address space at location 0x100000.  This is pretty handy in embedded coding where lots of registers might be mapped into the address space of the processor.  Now because I am supremely lazy, what if I didn't want to have to write all the pointer stuff in the defines.  I would like to define a macro like

#define MAKE_REG( r, a) #define r  (*(unsigned int *)(a))

Obviously I can put a define on the same line but what I want is to be able to write:
MAKE_REG( CRTL2, 0x1000020 );

And then use CRTL2 just like I did CTRL1.  Is there any way of achieving my result in ANSI C?

Oliver


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]