Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?
From: Måns Rullgård (mru_at_kth.se)
Date: 06/28/04
- Next message: Phlip: "Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?"
- Previous message: Gregor Copoix: "Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?"
- In reply to: Gregor Copoix: "Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?"
- Next in thread: Roger Willcocks: "Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?"
- Reply: Roger Willcocks: "Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Jun 2004 15:13:10 +0200
"Gregor Copoix" <logical@xeption.de> writes:
>> > 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;
>
>> You need to use the token merging operator (##) rather than stringification
>> operator (#), like this:
>
>> #define MAKE_VARNAME2(base, var,val) int var##_##base = val
>
> But this results still in an lvalue error as the concaternated text is a
> string for the preprocessor.
> int "var_module1" = 0;
> and results in an compiler error.
> I tried both # and ##.
Then your bug is somewhere else. It should work with ##.
-- Måns Rullgård mru@kth.se
- Next message: Phlip: "Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?"
- Previous message: Gregor Copoix: "Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?"
- In reply to: Gregor Copoix: "Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?"
- Next in thread: Roger Willcocks: "Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?"
- Reply: Roger Willcocks: "Re: Q: C macro's for lvalue statements ? Any C marco Guru's out there ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]