Boost logo

Boost :

From: Suman Cherukuri (suman_at_[hidden])
Date: 2005-08-29 16:48:47


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


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