Discuss A very novice question from newbie in the C Programming forum on Dev Shed. A very novice question from newbie C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Time spent in forums: 1 h 21 m 58 sec
Reputation Power: 0
A very novice question from newbie
I am a new member in this forum. I am an electronics hobbyist and presently working with hobby projects based on microcontroller. I have already completed some projects for which source code has been developed through assembly language. Now I am trying to enter into the world of higher language like C. A sample source code is given below. in the code two "while" loops are there. Please let me know if condition of first "while" loop is satisfied / not satisfied, where control will pass to. So far I know "while (1)" is an infinite loop. In this code which portion will be repeated indefinitely?
Time spent in forums: 1 Month 2 Weeks 1 Day 7 h 30 m 58 sec
Reputation Power: 1283
In this case, both loop will be infinite. In the first loop, you have the variable already set to 0, so as long as that's true, the loop will run. If the value changes, then control will pass to the next line.
Time spent in forums: 1 Month 3 Weeks 2 Days 9 h 25 m 16 sec
Reputation Power: 455
If you declared variables in the most straightforward way to have the code compile, it would iterate forever at
while (TMR2IF_bit == 0); // This is the first loop.
because the statement body is empty.
I suppose TMR2IF_bit could have extern linkage and volatile quality. As such an external event would let the program continue through to the second loop which runs forever. I'd write the last loop as
to conserve electrons. If you can't save electrons, no one can.
[code]Code tags[/code] are essential for python code!