473,498 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it implementation-defined whether this errors?

This is a test case I constructed for a vaporware standalone C99
preprocessor:

#if 1
#elif
#endif

The text did not permit quickly deciding whether the syntax relaxation
for preprocessing directives in blocks that aren't processed (C99 6.10
paragraph 4) dominates knowing what an elif-block actually was (C99
6.10 paragraph 1). If 6.10 paragraph 4 dominates, this should warn
(as the preprocessor got lucky). If C99 6.10 paragraph 1 dominates,
this should error.

The obvious complementary test case

#if 0
#elif
#endif

must error, as the control expression of the #elif is actually
needed. So I tentatively decided to make the first test case behave
like the obvious one: error [why should it only warn just because we
got lucky?].

When I ran my test suite against GCC's cpp, the first test case only
warned. Since this is a legitimate implementation: did I miss
something that guarantees that the syntax relaxation dominates knowing
that the elif-block is well-formed?
Aug 27 '08 #1
4 1217
za*****@zaimoni.com wrote:
This is a test case I constructed for a vaporware standalone C99
preprocessor:

#if 1
#elif
#endif

The text did not permit quickly deciding whether the syntax relaxation
for preprocessing directives in blocks that aren't processed (C99 6.10
paragraph 4) dominates knowing what an elif-block actually was (C99
6.10 paragraph 1). If 6.10 paragraph 4 dominates, this should warn
(as the preprocessor got lucky). If C99 6.10 paragraph 1 dominates,
this should error.
The question boils down to whether #elif by itself is a malformed
#elif directive (because there's no expression) or whether it's just
a non-directive (because it doesn't parse as a directive). 6.10p3
settles the issue:

"[...] A non-directive shall not begin with any of the
directive names appearing in the syntax."

That is, no line beginning with #elif can be a non-directive, so it
must be treated as a directive, and since an #elif alone does not
match the syntax of any preprocessor directive it's an error.
The obvious complementary test case

#if 0
#elif
#endif

must error, as the control expression of the #elif is actually
needed.
I see no difference between this example and the first one.

--
Er*********@sun.com
Aug 27 '08 #2
On Aug 27, 9:26 am, Eric Sosman <Eric.Sos...@sun.comwrote:
zaim...@zaimoni.com wrote:
This is a test case I constructed for a vaporware standalone C99
preprocessor:
#if 1
#elif
#endif
The text did not permit quickly deciding whether the syntax relaxation
for preprocessing directives in blocks that aren't processed (C99 6.10
paragraph 4) dominates knowing what an elif-block actually was (C99
6.10 paragraph 1). If 6.10 paragraph 4 dominates, this should warn
(as the preprocessor got lucky). If C99 6.10 paragraph 1 dominates,
this should error.

The question boils down to whether #elif by itself is a malformed
#elif directive (because there's no expression) or whether it's just
a non-directive (because it doesn't parse as a directive). 6.10p3
settles the issue:

"[...] A non-directive shall not begin with any of the
directive names appearing in the syntax."

That is, no line beginning with #elif can be a non-directive, so it
must be treated as a directive, and since an #elif alone does not
match the syntax of any preprocessor directive it's an error.
Yes -- *if* the #elif directive is being preprocessed.
The obvious complementary test case
#if 0
#elif
#endif
must error, as the control expression of the #elif is actually
needed.

I see no difference between this example and the first one.
Superficially:
Whether the first case's malformed #elif directive is actually being
preprocessed (as a top-level construct) is a "this sentence is false"
paradox. (If I'm going off-course, this is why.) With the second
case, it's a "this sentence is true" non-paradox.

We have to preprocess the #elif directive to determine that there is
an elif-block to not preprocess. (I chose to error at that point,
then discard the malformed elif-block.) But as the starting line of
the not-preprocessed elif-block we're not supposed to preprocess it
after all -- which trips the "any tokens allowed" override for blocks
that aren't preprocessed.
Aug 27 '08 #3
za*****@zaimoni.com wrote:
On Aug 27, 9:26 am, Eric Sosman <Eric.Sos...@sun.comwrote:
>zaim...@zaimoni.com wrote:
>>This is a test case I constructed for a vaporware standalone C99
preprocessor:
#if 1
#elif
#endif
The text did not permit quickly deciding whether the syntax relaxation
for preprocessing directives in blocks that aren't processed (C99 6.10
paragraph 4) dominates knowing what an elif-block actually was (C99
6.10 paragraph 1). If 6.10 paragraph 4 dominates, this should warn
(as the preprocessor got lucky). If C99 6.10 paragraph 1 dominates,
this should error.
The question boils down to whether #elif by itself is a malformed
#elif directive (because there's no expression) or whether it's just
a non-directive (because it doesn't parse as a directive). 6.10p3
settles the issue:

"[...] A non-directive shall not begin with any of the
directive names appearing in the syntax."

That is, no line beginning with #elif can be a non-directive, so it
must be treated as a directive, and since an #elif alone does not
match the syntax of any preprocessor directive it's an error.

Yes -- *if* the #elif directive is being preprocessed.
It is a directive, and it is not inside a skipped group, so
it is processed. The grammar of 6.10p1 makes it clear that the
#elif is not part of the if-group that is included or omitted by
the #if, but marks the start of the elif-group that follows the
if-group in the same if-section. Thus, 6.10.1p5 does not apply.
>>The obvious complementary test case
#if 0
#elif
#endif
must error, as the control expression of the #elif is actually
needed.
I see no difference between this example and the first one.

Superficially:
Whether the first case's malformed #elif directive is actually being
preprocessed (as a top-level construct) is a "this sentence is false"
paradox. (If I'm going off-course, this is why.) With the second
case, it's a "this sentence is true" non-paradox.
I'm also susceptible to going off-course, but you've not yet
convinced me that the course and I have become non-proximal ...
As I understand the matter, the #elif directive *is* processed, no
matter what the value of the controlling expression in the preceding
#if or #elif, because the #elif is not part of the group that the
preceding directive includes or suppresses.

6.10.1p5 applies to situations like this, which I think is
valid C despite its unusual appearance:

#if 0
#if *-*-*-*-*-*-*-*
#elif |-|-|-|-|-|-|-|
#elif <<<<<-=-=->>>>>
#endif you must this old grey head
#elif 0
#else
#endif

IMHO, the directives in the inner if-section -- fully contained within
the if-group of the outer if-section -- are processed only as far as
their names, as 6.10.1p5 says. The other four directives are, I think,
fully processed regardless of the control expressions' values.

--
Er*********@sun.com
Aug 27 '08 #4
On Aug 27, 12:32 pm, Eric Sosman <Eric.Sos...@sun.comwrote:
zaim...@zaimoni.com wrote:
On Aug 27, 9:26 am, Eric Sosman <Eric.Sos...@sun.comwrote:
zaim...@zaimoni.com wrote:
This is a test case I constructed for a vaporware standalone C99
preprocessor:
#if 1
#elif
#endif
>....
That is, no line beginning with #elif can be a non-directive, so it
must be treated as a directive, and since an #elif alone does not
match the syntax of any preprocessor directive it's an error.
Yes -- *if* the #elif directive is being preprocessed.

It is a directive, and it is not inside a skipped group, so
it is processed. The grammar of 6.10p1 makes it clear that the
#elif is not part of the if-group that is included or omitted by
the #if, but marks the start of the elif-group that follows the
if-group in the same if-section.
Agreed.
Thus, 6.10.1p5 does not apply.
6.10.1p5 entails the tie-breaker I needed, however.
>The obvious complementary test case
#if 0
#elif
#endif
must error, as the control expression of the #elif is actually
needed.
I see no difference between this example and the first one.
Superficially:
Whether the first case's malformed #elif directive is actually being
preprocessed (as a top-level construct) is a "this sentence is false"
paradox. (If I'm going off-course, this is why.) With the second
case, it's a "this sentence is true" non-paradox.
What I had not noticed: 6.10.1p5 entails that an #elif directive does
not suppress itself. This dispels the claimed paradox. (I plausibly
overlooked a more direct statement to that effect.)
....
6.10.1p5 applies to situations like this, which I think is
valid C despite its unusual appearance:
I'm certain your following example is valid C.
#if 0
#if *-*-*-*-*-*-*-*
#elif |-|-|-|-|-|-|-|
#elif <<<<<-=-=->>>>>
#endif you must this old grey head
#elif 0
#else
#endif

IMHO, the directives in the inner if-section -- fully contained within
the if-group of the outer if-section -- are processed only as far as
their names, as 6.10.1p5 says.
Yes, this is unequivocal.
Aug 27 '08 #5

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

Similar topics

9
4614
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
3
1531
by: Eric Chaves | last post by:
Hi fellows, According to the C# language specification (10.5.3), Every virtual method has a "most derived implementation" determined by a 3-step rule. If I invoke the virtual method from a normal...
1
3818
by: lewindha | last post by:
Hey guys I'm trying to populate a drop down list with values from a db table. When I view the page, the drop list is empty. Here is the code: private void populateClients() { string...
6
13666
by: Anders Borum | last post by:
Hello! I accidentally posted this as a reply to another posting. It is a seperate posting - sorry :-) I am programming a cloning service (which is essential to the framework), and am...
1
1137
by: Jack | last post by:
Hi, I am writing a COM server with ATL and VC++.NET. I wonder if there is a way to reuse COM method implementations without delegation, something like this: __interface IFoo : IDispatch { ...
8
2413
by: Jef Driesen | last post by:
I'm working on an image segmentation algorithm. An essential part of the algorithm is a graph to keep track of the connectivity between regions. At the moment I have a working implementation, but...
52
3689
by: lovecreatesbeauty | last post by:
Why the C standard committee doesn't provide a standard implementation including the C compiler and library when the language standard document is published? C works on the abstract model of low...
20
6039
by: Luc Kumps | last post by:
(Sorry about the previous post, it got transmitted before it was complete) We try to separate implementation and interface defintions, but we run into a problem. I hope the guru's can solve this,...
7
2043
by: desktop | last post by:
I the C++ standard page 472 it says that an associative container can be constructed like X(i,j,c) where i and j are input iterators to elements. But in the implementation there is no constructor...
6
3928
by: Ralph | last post by:
Hi, I was reading effictive C++ and some other books again and they all tell you about hiding implementation details (proxy/pimpl/inheritance) but they never really explain when to use it. I...
0
7002
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
7205
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...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.