[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Feature request - compiler warning for "if" stmtsthat
From: |
Dave Hansen |
Subject: |
Re: [avr-gcc-list] Feature request - compiler warning for "if" stmtsthat do nothing |
Date: |
Tue, 14 Dec 2004 09:51:36 -0500 |
From: Douglas Dotson <address@hidden>
--- Dave Hansen <address@hidden> wrote:
[...]
> My preference is something like
>
> while (*dst++ = *src++)
> continue;
Won't this generate extra code (an extra jump)? Or
does the optimizer take it out? My concern is that
No.
I wrote a small test file to check it out:
---begin include file ---
C:\Dave>type continue.c
void copy1(char *dst, const char *src)
{
while (*dst++ = *src++)
/*do nothing*/;
}
void copy2(char *dst, const char *src)
{
while (*dst++ = *src++)
continue;
}
---end included file---
Compiling with "avr-gcc -S" I get two identical functions 45 instructions
long.
Compiling with "avr-gcc -S -Os", each function is reduced to 9 instructions,
but they're still identical.
using the "continue" kind of obscures the meaning
of the code. One has to think about the intent rather
than the ; which is immedeately obvious.
I disagree. The lone semicolon is small, easily missed, and more likely to
be the result of a typo. The continue says "This iteration of the loop is
complete: continue with the next one." And as a skeptic, I trust code over
comments, which is why I prefer it to the "do nothing" comment
It's just about the only place the "continue" statement appears in my code.
Regards,
-=Dave
- Re: [avr-gcc-list] Feature request - compiler warning for "if" stmts that do nothing, (continued)
RE: [avr-gcc-list] Feature request - compiler warning for "if" stmts that do nothing, Douglas Dotson, 2004/12/13
RE: [avr-gcc-list] Feature request - compiler warning for "if" stmts that do nothing, Dave Hylands, 2004/12/20