Boost logo

Boost :

From: Graeme Prentice (gp.kiwi_at_[hidden])
Date: 2005-08-29 18:15:10


The body of a macro cannot contain preprocessor directives. Any time the
compiler sees a # as the first non whitespace character it says - this is a
preprocessor directive and not part of the macro body. Even if the # got
bound up in the macro body text, it would not have a newline preceding it as
the backslashes just "join" all the text together without any newlines in
between, i.e. the compiler does not look for preprocessor directives when
rescanning substituted text.

Maybe you could encode __LINE__ instead of reporting it directly and also
define a unique constant for each source file as well - instead of using the
filename. Your method wouldn't provide uniqueness across multiple
translation units anyway.

Graeme

> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Suman Cherukuri
> Sent: Tuesday, 30 August 2005 9:49 a.m.
> To: boost_at_[hidden]
> Subject: [boost] Preprocessot question
>
>
> This probably doesn't belong to boost mailing list, but since
> boost has a
> lot of support in preprocessor, there may be someone who can answer my
> question.
>
> I'm using general 'C' compiler in this project (hence I
> cannot use boost
> headers). I want to write a macro as follows;
>
> #define ERR(x, y) \
> { \
> # ifndef ERR##x \
> # define ERR##x \
> # else \
> # error ERR##x already defined\
> # endif
> y = x; \
> }
>
> When I compile, I get the error saying,
> error C2162: expected macro formal parameter
>
> on all the preprocessor lines inside the #define ERR(...) body.
>
> The reason I want to do something like this is to have some
> unique numbers
> in the code (like locators. Don't want to use __FILE__ and
> __LINE__ for
> security reasons) and want to capture duplicates at compiletime.
>
> For example if I say in the code, int err = 10000 in one
> file, I don't want
> any other engineer to use 10000 in the anywhere else in the code.
>
> So I started writing something like int err = ERR(10000) but got into
> several compiler problems as I mentioned above.
>
> Any suggeations?
>
> Thanks,
>
> --Suman
>
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk