Using 'continue' in Hi-Tech C

Status
Not open for further replies.

MrNobody

New Member
Hi,
I'm now learning to use Hi-Tech C. Previously, I use C18 compiler.

In Hi-Tech C, I'm trying to poll the GODONE bit in ADC. In the example, they use

while (GODONE) continue;

Is there any difference if I use while (GODONE); instead (without 'continue')? When I use the second one, it is able to build well without any error.

Please advice. Thanks.
 
Code:
while(GODONE);
is the way it's done. Standard practice. You can also do
Code:
while(GODONE){}
if you want.
 
Last edited:
I would either continue to use the continue statement or use the empty bracket set as the simple semi-colon terminator seems a little ambiguous, at least to me. Seeing as how all three lines of code perform the same function you can do it any which way you want.
 
I would use the semi colon version everytime. It is only ambiguous if you are not really familiar with C.

Mike.
 
I would use the semi colon version everytime. It is only ambiguous if you are not really familiar with C.

Mike.

Agreed, although I slightly prefer the empty-bracket version--probably just because a professor I liked 12 years ago used it. It's unambiguous even if you are not very familiar with C.

The "continue" version I would not use or recommend. Without the enclosing braces, the semantics might get tricky for the parser. Sounds like that might be the case with Hi-Tech C.


Torben
 
well, I always like only the semicolons, looks really simple!!
who knows, the Hi-tech people might be using 'continue' to improve radability!! but it can be achieved better with a comment! No need for continue there..

---------------
https://dharmanitech.blogspot.com
 
You say potato, I say potato. Wait... that little phrase doesn't work in text =\

Yeah, as far as ';' vs '{}' it's. . .er. . .6 of one, half a dozen of the other (there, found one for text!) .

The 'continue' one just looks suspicious to me, although gcc happily compiles it in ANSI mode. Huh.


Torben
 
I guess it's 'safer' to explicitly refer to the continue rather than rely on the compiler knowing what to do with it. It's a whole lot of gray area =)
 
I'd say it's a pretty broken compiler that gets while(GODONE); wrong, as long as GODONE is considered volatile (which I'm pretty sure it is).

Note that this may not work with a declared variable unless it was declared as volatile. An optimizer may get overzealous in the following case
Code:
unsigned char foo;
...
foo = 0;
while(foo);
...
 
Last edited:
Perhaps they use the continue as a means to avoid optimisation simply removing the entire statement.

I have seen things happen with optimisers like that with simple tests. It's always best to make sure the controlling statement uses a variable declared as volatile, especially if it can be changed by external influences, IRQ's for instance.

Ray
 
Oh.. umm.. thanks.. i didn't know that.. I'll try to remember to use 'continue' next time i use a non volatile variable.. If not i'll be wondering why my code is not working as it should. Thanks alot.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…