On 09/23/2014 04:30 AM,
dS...@arcor.de wrote:
> 23. September 2014 00:57:54 UTC+2, Derek M. Jones:
>>> returns 1 if translated by recent GCC compilers. I perceived this as erroneous and submitted a bug report, but that was rejected as invalid with the remark "#pragma are considered statements." Is the declaration of such syntactic significance of a preprocessing directive compatible with the C standard?
>>
>> Interesting reply from the gcc maintainer.
>>
>> Does the status of this #pragma as a statement mean that it can only
>> occur within a function definition?
>
> That's a good question. In fact, it is also accepted outside of a function.
>
>> The version of gcc I am using, 4.7.2, produces the 'expected' behavior.
>
> Interesting ... gcc 4.7.4 has the new, unexpected behaviour.
>
>> Sentence 132
http://c0x.coding-guidelines.com/5.1.1.2.html
>> makes life difficult for implementors of this behavior.
>
> That's nicely put.
>
>> What does gcc do? Does it cause #pragma to effectively
>> expand to a ; (semicolon), in which case this kind of
>> #pragma can occur anywhere a declaration can occur.
>
> No, the code I posted is already the preprocessed output (generated
> by the option -save-temps as well as -E), I only omitted file and line
> information and re-indented. So, the sentence 132 "All preprocessing
> directives are then deleted" has not been followed. Could the argument
> that the compiler must act as if the directive were deleted be brought
> forward?
It is normally required that pre-processing directives be deleted at the
end of translation phase 4 (5.1.1.2p4), long before statements are
parsed as such during translation phase 7 (5.1.1.2p7). However, the
implementation-defined consequences of ordinary #pragma directives
(6.10.6p1) are effectively unlimited - they can override anything that
should normally happen during or after translation phase 4 (since they
are not recognized as preprocessing directives until phase 4).
The only exception is for #pragma directives where the first
preprocessing token after the #pragmas is STDC (6.10.6p2). Those have
only standard-defined behavior, and therefore are not free to override
5.1.1.2. Do you see the same behavior with -std=c99 and
#pragma STDC FP_CONTRACT ON
if so, that's non-conforming behavior.
--
James Kuyper