Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!ittatc!dcdwest!sdcsvax!sdcrdcf!hplabs!hpda!hpisoa2!hpitg!ttrdc!levy@ttrdc From: levy@ttrdc Newsgroups: net.lang.c Subject: Re: Infinite Loops Message-ID: <854@ttrdc> Date: Wed, 30-Apr-86 04:50:00 EDT Article-I.D.: ttrdc.854 Posted: Wed Apr 30 04:50:00 1986 Date-Received: Tue, 13-May-86 01:16:55 EDT References: <8200004@ztivax> Lines: 69 In article <140@toram.UUCP>, roe@toram.UUCP writes: >In article <577@ur-helheim.UUCP> badri@ur-helheim.UUCP (Badri Lokanathan) writes: >>My question is the following: is there any reason (other >>than personal preferance) why one would prefer to use any particular form? >>I personally prefer the while(1) form since it seems to make better reading. >>Even better, I sometimes define TRUE to be 1 and then use while(TRUE). >Unless you have a very unique optimizer, it is usually better to use the >for(;;) form rather than the while(1) form. Reason is: while(1) is >ALWAYS evaluated (ie. : is 1 TRUE? if so, continue) before each iteration, >whereas for(;;) compiles as a simple branch or jump instruction with no >test and no conditional branch. > Roe Peterson What very unique optimizer? Here's what I get (SysV 3B20, cc -S [note no -O]): $ cat > while1.c main() /* while1.c */ { register int a=0; while (1) a++; } ^D$ cc -S while1.c $ cat while1.s .file "while1.c" .data .text .align 4 .def main; .val main; .scl 2; .type 044; .endef .globl main main: save &.R1 addw2 &.F1,%sp movw &0,%r8 .L14: addw2 &1,%r8 jmp .L14 ^^^^^^^^^^^^ .L13: .L12: ret &.R1 .set .R1,1 .set .F1,0 .def main; .val .; .scl -1; .endef .data $ cc -c while1.s $ dis while1.o **** DISASSEMBLER **** disassembly for while1.o section .text main() 0: 7a10 save &0x1,&0x0 2: 346c 0000 0000 000b addw2 &0x00000,%sp a: 1508 movw &0x0,%r8 c: 1118 addw2 &0x1,%r8 e: 9002 br -0x2 ^^^^^^^^^^^^^^^^ 10: 7b10 ret &0x1 12: dede nop -- ------------------------------- Disclaimer: The views contained herein are | dan levy | yvel nad | my own and are not at all those of my em- | an engihacker @ | ployer or the administrator of any computer | at&t computer systems division | upon which I may hack. | skokie, illinois | -------------------------------- Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa, vax135}!ttrdc!levy