Infinite loops
Daniel R. Levy
levy at ttrdc.UUCP
Wed Apr 30 09:50:24 AEST 1986
In article <140 at toram.UUCP>, roe at toram.UUCP writes:
>In article <577 at ur-helheim.UUCP> badri at 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 <c>
^^^^^^^^^^^^^^^^
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
More information about the Comp.lang.c
mailing list