Re: Simple question regarding the use of ;
- From: "Bartc" <bartc@xxxxxxxxxx>
- Date: Thu, 01 Jan 2009 11:20:31 GMT
"Stephen Sprunk" <stephen@xxxxxxxxxx> wrote in message
news:MgV6l.4136$jZ1.316@xxxxxxxxxxxxxxxxxxxxxxx
Andrew wrote:Hello,
I have been doing some microprocessor programming, and I have run into
some variations in the way people use the semi-colon. Please tell me
the difference between these two statements.
1. while(1)
{
value = read_adc(1);
}
2. while(1)
{
value = read_adc(1);
};
Is the semi-colon on statement 2 doing anything? The code seems to
A semicolon terminates a simple statement, as in "value = read_adc(1);". A
compound statement is enclosed by '{' and '}' and contains zero or more
simple or compound statement; there is no need for a ';' to terminate a
compound statement, because the '}' does that.
I'm not sure that was the reason. Otherwise you could say the last (simple) statement in a {...} block doesn't need a terminating semicolon because the } does that job too. Then the semicolon reverts to a statement separator.
I think that {...} statements not needing a semicolon terminator is just
another oddity of C.
--
Bartc
.
- Follow-Ups:
- Re: Simple question regarding the use of ;
- From: Stephen Sprunk
- Re: Simple question regarding the use of ;
- References:
- Re: Simple question regarding the use of ;
- From: Stephen Sprunk
- Re: Simple question regarding the use of ;
- Prev by Date: Re: Simple question regarding the use of ;
- Next by Date: Re: Zunes bug
- Previous by thread: Re: Simple question regarding the use of ;
- Next by thread: Re: Simple question regarding the use of ;
- Index(es):
Relevant Pages
|