![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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. | |
| |
| | (permalink) | |
| Quote:
Code: while(GODONE); Code: while(GODONE){}
__________________ ========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 30th August 2008 at 05:54 AM. | ||
| |
| | (permalink) |
| Futz is right. Continue works within loops where its effect is to force an immediate jump to the loop control statement. Lots of info on the web see http://cplus.about.com/od/learningc/...ssonfive_3.htm
__________________ search engine for electronic partsJunebug USB PIC programmer kit., USB Bit Wacker, 3v0's Homepage The 15 Minute Printed Circuit Board! (+drill time) Last edited by 3v0; 30th August 2008 at 06:00 AM. | |
| |
| | (permalink) |
| Thanks for the explanation. | |
| |
| | (permalink) |
| 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.
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." | |
| |
| | (permalink) |
| I would use the semi colon version everytime. It is only ambiguous if you are not really familiar with C. Mike. | |
| |
| | (permalink) | |
| Quote:
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
__________________ Curiosity was framed. Ignorance killed the cat. | ||
| |
| | (permalink) |
| 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.. --------------- http://dharmanitech.blogspot.com | |
| |
| | (permalink) |
| You say potato, I say potato. Wait... that little phrase doesn't work in text =\
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." | |
| |
| | (permalink) | |
| Quote:
The 'continue' one just looks suspicious to me, although gcc happily compiles it in ANSI mode. Huh. Torben
__________________ Curiosity was framed. Ignorance killed the cat. | ||
| |
| | (permalink) |
| 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 =)
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." | |
| |
| | (permalink) |
| 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 by philba; 31st August 2008 at 05:31 AM. | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) | |
| Quote:
Last edited by MrNobody; 1st September 2008 at 12:14 AM. | ||
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| New robotics tech | mous3 | Robotics Chat | 0 | 31st July 2008 03:07 AM |
| ICD2 woes continue... | Hank Fletcher | Micro Controllers | 12 | 16th June 2008 01:55 PM |
| Greetings Electro-tech. | xl5 | Chit-Chat | 4 | 29th December 2007 07:06 PM |
| a solution for a bell to continue playing music after releasing switch | Fahime | General Electronics Chat | 3 | 9th November 2006 11:26 AM |
| Electro-tech map!! | jrz126 | Chit-Chat | 83 | 12th January 2006 11:43 AM |