Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > /* #include <someyhing.h> */ => include it or do not include it?That is the question ....

Reply
Thread Tools

/* #include <someyhing.h> */ => include it or do not include it?That is the question ....

 
 
Andreas Bogenberger
Guest
Posts: n/a
 
      02-21-2008
Hi all,

I stumbled on the following example:

/*
#include <something.h>
#include <even_more.h>
*/

gpp expands the #include statements. I'm not really sure how to interpret
this correctly. As I got this like written above, I suppose it is working
on an other platform. However, I have found nothing in 6.4.9, 6.4.7
(however R3 mentions an undefined behavior if /* is between the braces or
double quotes of the include directive) or 6.10 and I am getting to the
conclusion that this is an undefined behavior. Is my assumption right?

best regards,
Andreas
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      02-22-2008
Andreas Bogenberger <(E-Mail Removed)> writes:

> Hi all,
>
> I stumbled on the following example:
>
> /*
> #include <something.h>
> #include <even_more.h>
> */
>
> gpp expands the #include statements.


[What is gpp -- a typo for gcc?]

> I'm not really sure how to interpret
> this correctly.


The standard lays out a sequence of translation phases that help make
this clear. The implementation must behave as if it have these
phases.

The two that relate to the above are 3 and 4:

3. The source file is decomposed into preprocessing tokens6) and
sequences of white-space characters (including comments). A
source file shall not end in a partial preprocessing token or in
a partial comment. Each comment is replaced by one space
character. New-line characters are retained. Whether each
nonempty sequence of white-space characters other than new-line
is retained or replaced by one space character is
implementation-defined.

4. Preprocessing directives are executed, macro invocations are
expanded, and _Pragma unary operator expressions are executed. If
a character sequence that matches the syntax of a universal
character name is produced by token concatenation (6.10.3.3), the
behavior is undefined. A #include preprocessing directive causes
the named header or source file to be processed from phase 1
through phase 4, recursively. All preprocessing directives are
then deleted.

It seems clear from this that phase 4 won't see any include directives
in your example -- just a space where the comment was.

> As I got this like written above, I suppose it is working
> on an other platform. However, I have found nothing in 6.4.9, 6.4.7
> (however R3 mentions an undefined behavior if /* is between the braces or
> double quotes of the include directive) or 6.10 and I am getting to the
> conclusion that this is an undefined behavior. Is my assumption
> right?


It is well-defined.

--
Ben.
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      02-22-2008
Andreas Bogenberger <(E-Mail Removed)> writes:
> I stumbled on the following example:
>
> /*
> #include <something.h>
> #include <even_more.h>
> */
>
> gpp expands the #include statements. I'm not really sure how to interpret
> this correctly. As I got this like written above, I suppose it is working
> on an other platform. However, I have found nothing in 6.4.9, 6.4.7
> (however R3 mentions an undefined behavior if /* is between the braces or
> double quotes of the include directive) or 6.10 and I am getting to the
> conclusion that this is an undefined behavior. Is my assumption right?


If the code is exactly as you posted it, then the include directives
are part of a comment and should be ignored.

My best guess is that the code is not exactly as you posted it, that
there's some subtle difference between the actual code and what you
posted (perhaps something you assumed was insignificant).

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Andreas Bogenberger
Guest
Posts: n/a
 
      02-22-2008
On Thu, 21 Feb 2008 23:05:51 -0800, Keith Thompson wrote:

> Andreas Bogenberger <(E-Mail Removed)> writes:
>> I stumbled on the following example:
>>
>> /*
>> #include <something.h>
>> #include <even_more.h>
>> */
>>
>> gpp expands the #include statements. I'm not really sure how to
>> interpret this correctly. As I got this like written above, I suppose
>> it is working on an other platform. However, I have found nothing in
>> 6.4.9, 6.4.7 (however R3 mentions an undefined behavior if /* is
>> between the braces or double quotes of the include directive) or 6.10
>> and I am getting to the conclusion that this is an undefined behavior.
>> Is my assumption right?

>
> If the code is exactly as you posted it, then the include directives are
> part of a comment and should be ignored.
>
> My best guess is that the code is not exactly as you posted it, that
> there's some subtle difference between the actual code and what you
> posted (perhaps something you assumed was insignificant).


gpp -> typo for cpp

your guess was of course right. I did not see a comment on one of the
include lines had a comment because line wrapping was off and it was far
to the right side of the screen.

thank you for your answers,
Andreas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long. rote ASP .Net 2 01-23-2008 03:07 PM
ASP Error 0126 include file not found, when using ".." in include file path Eric ASP General 10 01-11-2007 07:38 AM
ASP Error 0126 include file not found, when using ".." in include file path Eric ASP General 0 01-09-2007 06:54 PM
Re: the use of #include <a_file.h> v/s #include"a_file.cpp" Rolf Magnus C++ 2 11-28-2003 12:26 PM
#include "bar" negates #include <string> ; how to fix? Danny Anderson C++ 5 08-15-2003 06:38 PM



Advertisments