|
|
Subscribe / Log in / New account

What every C Programmer should know about undefined behavior

What every C Programmer should know about undefined behavior

Posted May 16, 2011 18:28 UTC (Mon) by iabervon (subscriber, #722)
In reply to: What every C Programmer should know about undefined behavior by cfischer
Parent article: What every C Programmer should know about undefined behavior #2/3

I think it's actually a reflex of being used to C99 (or gnu89), primarily. If you can avoid declaring a variable before where you initialize it, there is nowhere that the variable is in scope and uninitialized, meaning you (or someone else touching the code later) can't accidentally use it uninitialized. If you then have to write C89, the easy thing is to move the whole line, instead of splitting it, particularly when you don't think you care about the ordering of this code with respect to other code.

Of course, there's also the situation of a programmer who doesn't think C99 has caught on modifying a C99 codebase, and moving the line with the declaration up to the start of the block; the result may not be "natural" C89 to write, but it might be a "natural" C89 change to a "natural" C99 block.


to post comments

What every C Programmer should know about undefined behavior

Posted May 16, 2011 19:57 UTC (Mon) by jreiser (subscriber, #11027) [Link]

If you then have to write C89, the easy thing is to move the whole line, ...

Often it is better to make a block by inserting the braces which enclose the intended scope.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds