-
Using & in #define
I am trying to use some code from Ronald Mak's Writing Compilers & Interpreters:
Code:
#define enter_name_local_symtab(name, &symtab_display[level]) \
idp = enter_symtab(name, &symtab_display[level])
and this comes up with an error
"&" cannot be used in a macro parameter list. I note that this is used quite a bit in the book (the book is quite old, so the C will be outdated).
How do I get over this?
-
You put the complexity in when you call the macro, not when you declare it.
Code:
#define enter_name_local_symtab(a, b) \
idp = enter_symtab(a,b)
// then later, use the macro
enter_name_local_symtab(name, &symtab_display[level])
The macro parameters are just placeholders, to be replaced literally with the values used when you call the macro.
-
Have a look at: ftp://ftp.dante.de/tex-archive/support/ltx2x/l2xisymt.h where it has:
Code:
/**************************************************************************/
/* enter_name_local_symtab() enter the given name into the local symtab */
/* and set pointer to the entry */
#define enter_name_local_symtab(idp, name) \
idp = enter_symtab(name, &symtab_display[level])
/**************************************************************************/
I don't particularly like that very much at all but it will at least work assuming there is a variable 'level' in scope (that's the stupid part I don't like)
-
Thank you Salem and Hodor. I'll look at your suggestions and see how they work before I progress further.