Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   /* #include <someyhing.h> */ => include it or do not include it?That is the question .... (http://www.velocityreviews.com/forums/t593337-include-someyhing-h-include-it-or-do-not-include-it-that-is-the-question.html)

Andreas Bogenberger 02-21-2008 11:24 PM

/* #include <someyhing.h> */ => include it or do not include it?That is the question ....
 
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

Ben Bacarisse 02-22-2008 12:42 AM

Re: /* #include <someyhing.h> */ => include it or do not include it? That is the question ....
 
Andreas Bogenberger <alterratz@gmx.net> 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.

Keith Thompson 02-22-2008 07:05 AM

Re: /* #include <someyhing.h> */ => include it or do not include it? That is the question ....
 
Andreas Bogenberger <alterratz@gmx.net> 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) <kst-u@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Andreas Bogenberger 02-22-2008 10:53 AM

Re: /* #include <someyhing.h> */ => include it or do not includeit? That is the question ....
 
On Thu, 21 Feb 2008 23:05:51 -0800, Keith Thompson wrote:

> Andreas Bogenberger <alterratz@gmx.net> 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


All times are GMT. The time now is 01:09 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.