[comp.lang.c] Are definitions evaluated in order?

ross@spam.ua.oz.au (Ross Williams) (06/27/91)

Does C guarantee that it will evaluate declarations in order?

For example, is the following program guaranteed to output "3"?

   main()
   {
    int a=3;
    int b=a;

    printf("%d\n",b);
   }

And how about:

   main()
   {
    int a=3,b=a;

    printf("%d\n",b);
   }

Even if it is standard, does anyone know if it is practically portable
(i.e. do compilers as a rule evaluate in order).

I am asking because it would neaten up a lot of the code I am writing.
Without the order assumption, variables that are dependent on other
variables initialized in the same block have to be initialized using
assignments instead of at their declaration.

I don't just need a yes or a no, I need a specific reference to [K&R]
or the ANSI standard ([K&R] preferred as I don't have a copy of the
standard). Without a formal language spec reference, I won't have a
warm fuzzy feeling about it.

Thanks,

Ross Williams
ross@spam.ua.oz.au