Re: 3 Questions

From: George Greer (greerga@circlemud.org)
Date: 01/31/01


On Wed, 31 Jan 2001, Daniel A. Koepke wrote:

>> Any compiler that has any kind of decent optimization will eliminate
>> any efficiency benefit that decalring a variable mid-function has.
>
>That's a generally false assumption.  Any time an expression can have a
>side-effect, the compiler cannot reasonably reorder it because it could
>break the code following it.

If you want variables in the middle of functions, then your functions are
too fat.

That doesn't include "throw-away" variables like loop iterators.  Those we
really don't care about beyond one little scope and it's nicer to write:

        for (int x = 0; ...) {

instead of:

        {
          int x;
          for (x = 0; ...) {

and it gets the "throw-away" point across better than declaring them with
the rest of the variables.

>Portability and standards are not one and the same.

As a recent entry to the International Obfuscated C Contest wrote:

--- 8< ---
    What it does
    ------------

    This program plots the positions of the four Galilean moons of Jupiter,
    as seen from earth. It doesn't correct for your location on earth, but I
    assure you that the parallax is minimal!

    [...]

    6. The code definitely is not portable - it will produce incorrect results
       if run from the surface of Mars.
--- 8< ---

:)

--
George Greer
greerga@circlemud.org

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/03/01 PST