Re: Unobvious coding error in C
On 30/12/2004, at 7:37 AM, M. Carlson wrote:
> On Wednesday, December 29, 2004, at 04:47 PM, Timothy J. Wood wrote:
>> On Monday, December 27, 2004, at 04:47 PM, Alex Majora wrote:
>>> for (j=0;j<5,k<100;j++,k++) {
>> You should probably log a bug against the compiler here if it
>> didn't emit a warning (or, you should turn on all possible -W flags
>> and -Werror). The "," operator should warn, I think, if its first
>> argument can be known to have no side effects.
>
> Um, can somebody explain to us newbies why the j<5 has no effect?
Because C is a very badly designed language with lots of these kinds of
gotchas, which should not be in any widely used language in the 21st
century. C is the underlying reason why today's operating systems,
especially windows are so flaky. Fortunately for OS X, Unix has
undergone more trial by fire.
> Why does only the last part "k<100" have an effect on the loop?
Because that's how C defines it... silly isn't it! Both C and C++ seem
to go to great lengths to make any syntax permissible by resort to all
kinds of crazy sematics. Hence the chronic state of the programming
profession today. C is the Windows of programming languages – bad
design gone crazy, propped up by a virtual monopoly.