This is the mail archive of the
mailing list for the GCC project.
Frank Klemm wrote:
> On Mon, Sep 17, 2001 at 11:59:28PM +0100, Neil Booth wrote:
> > > It is not allowed to compose numbers with '_' inside of macros.
> > >
> > > #define MILLION _MERGE5 ( 1, _, 000, _, 000 )
> > >
> For instance you have a program which uses _ in numbers.
> But not all compilers will will support this in the beginning.
> It should be possible to write a program which removes these _ inside of
> numbers to allow to compile such source files with other compilers.
> Without this rule it is impossible to write such a program without
> preprocessing the source file. And preprocessed files are no source files
> To prevent this it is forbidden to use this feature in conjunction with
> token concatenation. At least as long as this is not an ISO standard.
> For instance try to convert
> #define MILLION MY_MERGE_5 ( 1, _, 000, _, 000 )
If you are using the underscore to make numbers more readable, then
using a macro like this doesn't seem to me to be a step in the right
direction. This looks (to me) to be harder to understand than a
simple '1000000' would be.
Another option for this that I'd prefer would be to write
#define MY_MERGE_3(a,b,c) (a*1000000 + b*1000 + c)
#define MILLION MY_MERGE_3(1,000,000)
which doesn't need the extension, and you get to use comma's as the
separator which is what people normally expect. This example is
somewhat stupid, in that the million (1000000) constant is also
the MY_MERGE_3 definition, but you still get the idea.
> to the old representation. Note that MY_MERGE_5 is a self defined macro.
Someone could write a "preprocessor" in C (which you should have a
compiler for since you are trying to compile C code) that would
filter out the underscores in numbers. Then you could distribute
it along with your code for those running the wrong C compiler.
Not the greatest solution, but I'd think it would be better to
either use the extension or not.