Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.
 
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
 
You say potato, I say potato. Wait... that little phrase doesn't work in text =\
 
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
 
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);
...
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top