Re: Q: C macro's for lvalue statements ? Any C marco Guru's out
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Re: Q: C macro's for lvalue statements ? Any C marco Guru's out




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Re: Q: C macro's for lvalue statements ? Any C marco Guru's out  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-28-04 01:59 PM

"Gregor Copoix" <logical@xeption.de> writes:

> Hi everybody,
>
> I've got a problem implementing some macros that would make my code much
> more readable.
>
> The idea:
> I have a set of macros that create variable names depending of the content
> of some other define.
>
> An example (of how it should look like in the end):
>
> // ---------------  cut
> #define BASE_NAME module1
>
> // the macro(s) which I need help for :-)
> #define MAKE_VARNAME2(base, var,val) int var#_#base = val
> #define MAKE_VARNAME(var, val) MAKE_VARNAME2(BASE_NAME, var, val)
>
> // the usage example
> MAKE_VARNAME(status, 0);
> // ---------------  cut
>
> which should expand to
>
> int status_module1 = 0;
>
> I know, with the macro above this doesn't work so far, but is there a way 
to
> generate lvalue names (like variable names) with C macros (like in the
> example above) ?
> The main problem is, that any string processing in macros generate real
> strings (with  ""around) and the compiler doesn't accept them as lvalue -
> and now I am unfortunetly out of ideas.

You need to use the token merging operator (##) rather than stringification
operator (#), like this:

#define MAKE_VARNAME2(base, var,val) int var##_##base = val

> So it would be very helpful if there's any C macro guru out there who coul
d
> help m with this problem.
>
> And by the way: Is there a way to #define anything within a #define ?

No.

--
Måns Rullgård
mru@kth.se





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:11 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register