473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

preprocessor implementation GURU question

I'm trying to resolve a disagreement between friends --Digital Mars
and BOOST-- about what the precompiler should do in a given situation:

The problem arose when I was trying to compile a boost example program
with the DM compiler, and the name of a file which was put together by
a set of macros, ended up as,

....\...\list10 .cpp
vs.
....\...\list10.cpp

(notice the space before the period)

The macro where the problem occurs is in a file called
"...boost\mpl\list.hpp", which goes:

# define MPL_AUX_LIST_HEADER
BOOST_PP_CAT(list,BLAH_LIST_SIZE).hpp \
/**/

which I was able to work-around by adding the ##, such as:
BOOST_PP_CAT(list,BLAH_LIST_SIZE)##.hpp \
/**/

I reported the problem to boost mailing list, and they said that the
compiler shouldn't be adding a space.

I reported this to the Digital Mars people and they say that the only
legal way to concatenate is with ##.

I reported again to boost, and they say that the above does not
involve concatenation, as it does not cause tokens to merge.

I reported this to DM and they insist that that is the old kludge of
'concatenation by juxtaposition'.

I reported this to boost and they say the DM compiler is relying on
the old kludge of pure textual processing, whereas tokenization should
happen first.

I think I agree with boost. Given,

#defina a(x) x
a(the_file).ext

should result in

the_file.ext

But then I'm not sure what the compiler should do if I write,

a(the_file)ext //no dot

Could someone please shed light on this issue before they shoot the
messenger? >:^0 Thanks in advance.

Jul 22 '05 #1
9 1467
Dan W. wrote:
....

I think I agree with boost. Given,

#defina a(x) x
a(the_file).ext

should result in

the_file.ext

But then I'm not sure what the compiler should do if I write,

a(the_file)ext //no dot

Could someone please shed light on this issue before they shoot the
messenger? >:^0 Thanks in advance.


I don't know what the right answer is, however, you need to boost.

a) Shoot boost because the usage of this kind of behaviour is so
uncommon that you're bound to raise issues like this. If boost relies
on bug prone features, it's use is going to be limited.

b) I'm not sure, you might need to shoot DM. They should be considering
the possibility they might be wrong. "##" has been the standard way of
concatenating for a while, I suspect that this is probably more
universally supported than what boost is relying on.

Jul 22 '05 #2
Dan W. wrote in news:ce********************************@4ax.com:

[snip]
I think I agree with boost. Given,

#defina a(x) x
a(the_file).ext

should result in

the_file.ext

But then I'm not sure what the compiler should do if I write,

a(the_file)ext //no dot


It should produce the output "the_fileext" (not the quotes), however
this is 2 preproesor tokens (though only one C++ identifier). Add:

#define the_fileext Expansion
#define B() a(the_file)

B()

should produce: "the_fileext" Not "Expansion".

I.e. juxtaposition is fine for producing C++ tokens but not for
preprocessor tokens (i.e. tokens that can themselves be expanded).

The pre ## way was something like:

#define cat(a, b ) a/**/b
#define XY Expanded

cat(X, Y)

produced "Expanded".

This is what (IMO) ## was designed to fix.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #3
On 03 Dec 2003 16:23:57 EST, Gianni Mariani <gi*******@mariani.ws>
wrote:
I don't know what the right answer is, however, you need to boost.

a) Shoot boost because the usage of this kind of behaviour is so
uncommon that you're bound to raise issues like this. If boost relies
on bug prone features, it's use is going to be limited.

b) I'm not sure, you might need to shoot DM. They should be considering
the possibility they might be wrong. "##" has been the standard way of
concatenating for a while, I suspect that this is probably more
universally supported than what boost is relying on.


Yeah, I'd shoot them both; I just don't want Armageddon to start over
a blank space ;-)

But the thing is, the boost guys may be right. What they say is that
tokenization should come before macro substitution, and that the use
of ## is prescribed only for situations where tokens, otherwise
separated by white space, should be forcibly violated into a merger.
Juxtaposing ".ext" does not violate the tokens, therefore does not
justify the use of ##. So, making the macro like

#define filename(name,num,ext) name##num##.##ext

would not exactly be right either; maybe it shouldn't even compile.
And yet I see DM's point: Allowing,

#defina a(x) x
a(b)c
would produce
bc
and therefore allow concatenation by juxtaposition.

But then again, this may not be the precomp's responsibility. The
boost guy said, paraphrasing, "Show me one place in the entire
Standard where it says that the compiler should add a space."

And the thing is, I wouldn't know what the Standard looks like if I
stepped on it. (I should get a copy, one of these days.)

Cheers!
Jul 22 '05 #4
>The pre ## way was something like:

#define cat(a, b ) a/**/b
#define XY Expanded

cat(X, Y)

produced "Expanded".

This is what (IMO) ## was designed to fix.

Rob.


Wow! My head is spinning. Ok, you're saying that in the old days a
macro could modify the instance of another macro before the latter was
applied. But I thought that was the way it is currently, isn't it?
Would your last example NOT do that now? And how does ## prevent...
what exactly?
Maybe if you could give me a 4-way example: What worked and didn't
work / then and now. Thx.
Jul 22 '05 #5
Dan W. wrote in news:37********************************@4ax.com:
The pre ## way was something like:

#define cat(a, b ) a/**/b
#define XY Expanded

cat(X, Y)

produced "Expanded".

This is what (IMO) ## was designed to fix.

Rob.


Wow! My head is spinning. Ok, you're saying that in the old days a
macro could modify the instance of another macro before the latter was
applied. But I thought that was the way it is currently, isn't it?
Would your last example NOT do that now? And how does ## prevent...
what exactly?
Maybe if you could give me a 4-way example: What worked and didn't
work / then and now. Thx.


The problem with this method is when the C standard came out it
required comments to be replaced with a single space character.

Presumably this was so you couldn't write print/* whatever */f( "\n" );
and have the compiler see printf( "\n" );

So code that relied on this behaviour needed another way of achiving
the same thing hence the invention of ##.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #6
>The problem with this method is when the C standard came out it
required comments to be replaced with a single space character.

Presumably this was so you couldn't write print/* whatever */f( "\n" );
and have the compiler see printf( "\n" );

So code that relied on this behaviour needed another way of achiving
the same thing hence the invention of ##.


Ahhh! I see now. Thanks!
Jul 22 '05 #7
"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:Xn**********************************@195.129. 110.200...
It should produce the output "the_fileext" (not the quotes), however
this is 2 preproesor tokens (though only one C++ identifier). Add:


No. It is two preprocessing tokens *and* two identifier tokens. Each
preprocessing token is converted directly to a token--there is no
retokenization.

Regards,
Paul Mensonides
Jul 22 '05 #8
Paul Mensonides wrote in news:UL********************@comcast.com:
"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:Xn**********************************@195.129. 110.200...
It should produce the output "the_fileext" (not the quotes), however
this is 2 preproesor tokens (though only one C++ identifier). Add:


No. It is two preprocessing tokens *and* two identifier tokens. Each
preprocessing token is converted directly to a token--there is no
retokenization.


Right so the only way to write a preprocessor as a separate
programme is to introduce a space as the DM one does.

But with:

#define A() <c
#define B(X) X
#define C() >
#define INC(X) A()B(X)C()

#include INC(stdio)

since the expansion can always be internal it should include <cstdio>
not <c stdio>.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #9

"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:Xn**********************************@195.129. 110.130...
Paul Mensonides wrote in news:UL********************@comcast.com:
"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:Xn**********************************@195.129. 110.200...
It should produce the output "the_fileext" (not the quotes), however
this is 2 preproesor tokens (though only one C++ identifier). Add:


No. It is two preprocessing tokens *and* two identifier tokens. Each
preprocessing token is converted directly to a token--there is no
retokenization.


Right so the only way to write a preprocessor as a separate
programme is to introduce a space as the DM one does.

But with:

#define A() <c
#define B(X) X
#define C() >
#define INC(X) A()B(X)C()

#include INC(stdio)

since the expansion can always be internal it should include <cstdio>
not <c stdio>.


Yes, but the whitespace can only be inserted *after* the preprocessor does what
it normally does. E.g. when the preprocessing tokens are output to a text
stream.

Regards,
Paul Mensonides
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: qazmlp | last post by:
I hope comp.lang.c will not find the following question as a complete off-topic. I would like to remove ie.comment out the 'cout' statements during compilation(actually preprocessing) time. ...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
13
by: seemanta dutta | last post by:
Greetings C gurus, I have used preprocessor directives since a very long time. But whenever I see some professional piece of C code, the linux kernel for example, I get literally confused by the...
13
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int...
9
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour....
32
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input...
6
by: Amigo | last post by:
Hello all! I started working on an embedded project a few ago on Freescale 16-bit micro with an IAR toolset. Running PolySpace for the project code highlighted amongst other things a peculiar...
8
by: mohdalibaig | last post by:
C preprocessor generates the expanded version of our source code. In order to view this expanded code, I made use of the command cpp filename.c on the dos prompt. This command generates a file of...
31
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.