Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Question about a C code (why the do-while loop?)

Status
Not open for further replies.

alsig

Junior Member level 1
Joined
Jan 17, 2005
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
160
C question

Hi,

I stumbled upon this code

Code:
#if !defined(USE_INTERRUPTS)
#define Init()    
#else                    
#define Init()                      do { InitTMR2();\
                                    } while (0)

and I don’t understand why the do-while loop is used. Why not just skip it?

By the way I’m not sure this is the right forum, sorry

Alsig
 

jshroff

Advanced Member level 4
Joined
Apr 30, 2004
Messages
116
Helped
14
Reputation
28
Reaction score
0
Trophy points
1,296
Activity points
939
Re: C question

Sure, you can skip the while no need for that here
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
637
Reputation
1,272
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,183
C question

It may be leftover debugging code. The programmer can make the loop spin forever by simply changing the 0 to 1.
 

Ace-X

Advanced Member level 2
Joined
Jan 25, 2002
Messages
529
Helped
41
Reputation
82
Reaction score
14
Trophy points
1,298
Location
Germany
Activity points
5,150
Re: C question

echo47 said:
It may be leftover debugging code. The programmer can make the loop spin forever by simply changing the 0 to 1.

What could be the reason to make timer initialization (InitTMR2) forever? ;-)

I think this is just phantom stubs code. Just delete this "do-while".
Also, I think the following article will be helpful for everyone. I read it with pleasure.
https://www.nedbatchelder.com/text/deleting-code.html
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top