Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Legal C or bug in gcc

Reply
Thread Tools

Legal C or bug in gcc

 
 
Micah Cowan
Guest
Posts: n/a
 
      02-28-2008
Richard Heathfield wrote:
> CBFalconer said:
>
>> MisterE wrote:
>>>> if (1 == 1) a = 1;
>>> The semicolon brings the if to an end.

>> In Pascal. Not in C. In C the definitive thing is the presence of
>> a following 'else'.

>
> If that is true, the following code will compile, and will *not* print
> "Hmmm". Otherwise, the compilation will fail.


...."presence of [an immediately] following 'else'."...

Howzat?

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      02-28-2008
In article <(E-Mail Removed)>,
CBFalconer <(E-Mail Removed)> wrote:

>>> if (1 == 1) a = 1;


>> The semicolon brings the if to an end.


>In Pascal. Not in C. In C the definitive thing is the presence of
>a following 'else'.


In C, the definitive thing is matching the grammar, which in this case
means that you can't just look for an else, a semicolon, or a closing
brace. You have to look for the end of the "then" part, then look to
see if there's an else immediately following.

-- Richard
--
:wq
 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      02-28-2008
Richard Heathfield wrote:
> CBFalconer said:
>> MisterE wrote:
>>>
>>>> if (1 == 1) a = 1;
>>>
>>> The semicolon brings the if to an end.

>>
>> In Pascal. Not in C. In C the definitive thing is the presence of
>> a following 'else'.

>
> If that is true, the following code will compile, and will *not* print
> "Hmmm". Otherwise, the compilation will fail.
>
> #include <stdio.h>
>
> int main(void)
> {
> int a = 0;
> if(1 == 1)
> a = 1;
> printf("Hmmm\n");
> else
> NULL;
> return 0;
> }


That has a following printf, not a following else. As you knew
anyhow. However, in Pascal:

IF true THEN a := 1;
ELSE (* anything *)

will bring up large compiler screams at the ELSE. Remove the semi
and all is well.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      02-28-2008
CBFalconer said:

> Richard Heathfield wrote:
>> CBFalconer said:
>>> MisterE wrote:
>>>>
>>>>> if (1 == 1) a = 1;
>>>>
>>>> The semicolon brings the if to an end.
>>>
>>> In Pascal. Not in C. In C the definitive thing is the presence of
>>> a following 'else'.

>>

<snip>

>> if(1 == 1)
>> a = 1;
>> printf("Hmmm\n");
>> else
>> NULL;
>> return 0;
>> }

>
> That has a following printf, not a following else.


Er, that else sure looks like a following else to me.

Here's another counter-example:

int main(void)
{
if(1 == 1)
return 0;
}

According to you, that 'if' has no end (because there is no following
'else' present).

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      02-28-2008
Richard Heathfield wrote:

>>> if(1 == 1)
>>> a = 1;
>>> printf("Hmmm\n");
>>> else
>>> NULL;
>>> return 0;
>>> }

>> That has a following printf, not a following else.

>
> Er, that else sure looks like a following else to me.


No, the else is following the printf.

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      02-28-2008
Mark McIntyre said:

> Richard Heathfield wrote:
>
>>>> if(1 == 1)
>>>> a = 1;
>>>> printf("Hmmm\n");
>>>> else
>>>> NULL;
>>>> return 0;
>>>> }
>>> That has a following printf, not a following else.

>>
>> Er, that else sure looks like a following else to me.

>
> No, the else is following the printf.


Yes, and the printf is following the assignment, and the assignment is
following the 'if'.

You know what I mean, and I know what you mean. The point is that the
original claim was not only ambiguous but also incorrect. An 'if' is *not*
terminated by an 'else', but by the statement that follows it and,
*optionally*, an 'else'.

The grammar is:

selection-statement:
if ( expression ) statement
if ( expression ) statement else statement


--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      02-28-2008
Richard Heathfield wrote:
> Mark McIntyre said:
>
>> Richard Heathfield wrote:
>>
>>>>> if(1 == 1)
>>>>> a = 1;
>>>>> printf("Hmmm\n");
>>>>> else
>>>>> NULL;
>>>>> return 0;
>>>>> }
>>>> That has a following printf, not a following else.
>>> Er, that else sure looks like a following else to me.

>> No, the else is following the printf.

>
> Yes, and the printf is following the assignment, and the assignment is
> following the 'if'.
>
> You know what I mean, and I know what you mean.


Then why continue to argue? You made your (valid) point in the first
post, the rest has IMHO been posturing.
 
Reply With Quote
 
Antoninus Twink
Guest
Posts: n/a
 
      02-28-2008
On 28 Feb 2008 at 22:16, Mark McIntyre wrote:
> Richard Heathfield wrote:
>> Mark McIntyre said:
>>
>>> Richard Heathfield wrote:
>>>
>>>>>> if(1 == 1)
>>>>>> a = 1;
>>>>>> printf("Hmmm\n");
>>>>>> else
>>>>>> NULL;
>>>>>> return 0;
>>>>>> }
>>>>> That has a following printf, not a following else.
>>>> Er, that else sure looks like a following else to me.
>>> No, the else is following the printf.

>>
>> Yes, and the printf is following the assignment, and the assignment is
>> following the 'if'.
>>
>> You know what I mean, and I know what you mean.

>
> Then why continue to argue? You made your (valid) point in the first
> post, the rest has IMHO been posturing.


Miaow!

Even Psycho Mackintyre has finally realized that HeathField goes in for
posturing in a big way.

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      02-29-2008
Richard Heathfield wrote:
> CBFalconer said:
>> Richard Heathfield wrote:
>>> CBFalconer said:
>>>> MisterE wrote:
>>>>>
>>>>>> if (1 == 1) a = 1;
>>>>>
>>>>> The semicolon brings the if to an end.
>>>>
>>>> In Pascal. Not in C. In C the definitive thing is the presence of
>>>> a following 'else'.
>>>

> <snip>
>
>>> if(1 == 1)
>>> a = 1;
>>> printf("Hmmm\n");
>>> else
>>> NULL;
>>> return 0;
>>> }

>>
>> That has a following printf, not a following else.

>
> Er, that else sure looks like a following else to me.
> Here's another counter-example:
>
> int main(void)
> {
> if(1 == 1)
> return 0;
> }
>
> According to you, that 'if' has no end (because there is no following
> 'else' present).


I said 'definitive thing', not 'end'. And was talking about the
presence/absence of the following 'else'. I don't think I have
been sloppy this time. Also don't count line endings as
significant in either language. They're all white space.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      02-29-2008
CBFalconer said:

> Richard Heathfield wrote:


<snip>

>> if(1 == 1)
>> return 0;
>> }
>>
>> According to you, that 'if' has no end (because there is no following
>> 'else' present).

>
> I said 'definitive thing', not 'end'.


Look at the context - the thing to which you were replying was: "The
semicolon brings the if to an end." You said that this was true in Pascal
but not in C, and /then/ said: "In C the definitive thing is the presence
of a following 'else'." The obvious way to read this is that you were
claiming the presence of the following 'else' is the definitive thing that
marks the end of the 'if'.

If you didn't mean that, fine, we're arguing over nothing, so let's stop.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
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
Gcc 3.4.X to Gcc 4.1.X upgrading kas C++ 1 04-22-2010 08:56 PM
GCC 3.4.3 and GCC 4.1.2 ashnin C++ 1 07-07-2008 01:10 PM
Template construction in old gcc 3.3.3 does not compile in gcc 3.4.4 eknecronzontas@yahoo.com C++ 5 09-17-2005 12:27 AM
gcc 2.95 and gcc 3.2 gouqizi.lvcha@gmail.com C++ 8 03-16-2005 02:34 AM
C99 structure initialization in gcc-2.95.3 vs gcc-3.3.1 Kevin P. Fleming C Programming 2 11-06-2003 05:15 AM



Advertisments