[Info-vax] decrementing & for loops in C

Bill Gunshannon billg999 at cs.uofs.edu
Thu Jan 8 13:57:47 EST 2009


In article <176uZD2KcidF-pn2-D8mYDeIDpjtv at rikki.tavi.co.uk>,
	"Bob Eager" <rde42 at spamcop.net> writes:
> On Thu, 8 Jan 2009 16:32:24 UTC, billg999 at cs.uofs.edu (Bill Gunshannon) 
> wrote:
> 
>> In article <176uZD2KcidF-pn2-n85UEkyTHLOR at rikki.tavi.co.uk>,
>> 	"Bob Eager" <rde42 at spamcop.net> writes:
>> > On Thu, 8 Jan 2009 16:01:13 UTC, billg999 at cs.uofs.edu (Bill Gunshannon) 
>> > wrote:
>> > 
>> >> In article <6sml69F71m8lU1 at mid.individual.net>,
>> >> 	billg999 at cs.uofs.edu (Bill Gunshannon) writes:
>> >> >
>> >> >                                Maybe I will try some of the compilers I
>> >> > have to see if one of them actually does it.
>> >> 
>> >> OK, I tried it with GCC on x86.  I tried using both "=" and "=="
>> >> with and without the "-O" option.
>> >> 
>> >> Results:
>> >> 
>> >> == & no optimization:  Loop is there but condition to execute loop never
>> >>                        exists.
>> >> 
>> >> = & no optimization:   Loop code not even generated.
>> >> 
>> >> == & "-O":  Loop code including loop setup optimized out of code.
>> >> 
>> >> = & "-O":  Loop code including loop setup optimized out of code.
>> >> 
>> >> So, GCC at least can tell the logic does not allow for execution of the
>> >> loop and takes the appropriate action.  Sadly, it does not contain code
>> >> the cause the computer to reach out and slap the programmer on the back
>> >> of the head.
>> > 
>> > Try using:      gcc -Wparentheses ...
>> 
>> That option causes no change in the generated assembler source.
>> What is it supposed to do?  It looks like it would warn about
>> unmatche parentheses, which is not a problem in this program.
>> (I am not well versed on all the wacky crap that GNU thought
>> compilers should have.)
> 
> If there is an assignment within the for() condition, it will warn about
> it.

Ah...  Tried a different one of my test examples.  I got it.
Another case of the programmer relying on the compiler for
soemthing that should have been his job.  Am I the only one
that sees adding all this extra stuff to the compiler as a bad
thing as it makes the programmers lazier and then lets bugs thru
that a human would catch if they actually took the time to
review their code instead of trusting a machine to find all
their mistakes?

bill
 

-- 
Bill Gunshannon          |  de-moc-ra-cy (di mok' ra see) n.  Three wolves
billg999 at cs.scranton.edu |  and a sheep voting on what's for dinner.
University of Scranton   |
Scranton, Pennsylvania   |         #include <std.disclaimer.h>   



More information about the Info-vax mailing list