aliasing quotes in macros? 
Author Message
 aliasing quotes in macros?

Quote:

> Ordinarily the C preprocessor doesn't perform macro expansions
> within quoted strings.  But what if you have an application in which
> you DO want the preprocessor to perform a macro expansion within a
> string?

> For example:

>    typedef enum {
>       VALUE_1,
>       VALUE_2,
>       VALUE_3
>    } my_enumtype;

>    #define MY_MACRO(parm) printf("the value of parm is %d", parm);

>    main () {
>       MY_MACRO(VALUE_1);
>    }

> The output i'd like to see is:

>    the value of VALUE_1 is 0

> But because the preprocessor won't expand the first occurrance of
> parm (per K&R page 86), the actual output of this macro is:

>    the value of parm is 0

> Anybody know a clever trick for faking out the preprocessor so it
> will do this?

  #define MY_MACRO(parm) printf("the value of " #parm " is %d", parm)

Michael M Rubenstein



Sat, 25 Mar 2000 03:00:00 GMT  
 aliasing quotes in macros?


Quote:

>Ordinarily the C preprocessor doesn't perform macro expansions
>within quoted strings.  But what if you have an application in which
>you DO want the preprocessor to perform a macro expansion within a
>string?
>Anybody know a clever trick for faking out the preprocessor so it
>will do this?

look up the stringizer operator #


Sat, 25 Mar 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. aliasing single quotes in macros

2. Quote as argument to macro

3. Need Portable way to quote an argument in a macro

4. Preprocessor macro to quote its argument

5. define macros (with quotes and spaces) in VC6 ide's project setting page

6. macro replacement in quoted strings

7. macro replacement in quoted strings

8. Parsing quotes and double quotes

9. Aliasing through union, C++ vs. C

10. ANSI aliasing rules

11. Aliasing question...

12. Aliasing in ANSI C

 

 
Powered by phpBB® Forum Software