Mail Archives: djgpp/1994/10/16/07:55:44
This doesn't belong on the DJGPP list. Get a good C book (K&R 2d ed,
Harbison and Steele are both good), maybe Stroustrup's book on C++,
too, and read them all the way through.
Which FINALLY leads to my questions: Have I done something which
resulted in an invalid installation, is this a bug in the djgpp
code, does my having gpp installed without libraries loaded affect
the distribution, or is it not a c standard for all arguments of a
function (printf in this case) to be evaluated from left to right?
In C, for efficiency reasons, you are NOT allowed to rely on the order
of evaluation of the arguments of a function call (or across
assignment operators or commutative or associative operators, etc).
In fact, most C compilers push arguments from right to left in order
to simplify the programming of variadic functions like printf (note
that in this case the return address will be top of stack, and
immediately below it you will find the pointer to the format string).
However, many C++ compilers push arguments from left to right for
fixed argument functions, but switch to the right to left approach for
variadic functions.
With a good optimizer, it is possible that
int temp = match(a,b);
printf("Match results: Match at %d marker at %d\n",temp,marker);
would effectively result in *exactly* the same order of instructions
as the left to right evaluation of arguments. The difference is that
(oops, this is from Stroustrup's book, but I believe ANSI C also
mandates it) the assignment to the explicit temporary variable
guarantees the order of evaluation (although there is no guarantee
that the temporary variable will not be optimized into oblivion).
+-----------------------------------------------------------------------+
| Stephen Turnbull |
| University of Tsukuba, Institute of Socio-Economic Planning |
| Tennodai 1-chome 1--1, Tsukuba, Ibaraki 305 JAPAN |
| Phone: +81 (298) 53-5091 Fax: +81 (298) 55-3849 |
| Email: turnbull AT shako DOT sk DOT tsukuba DOT ac DOT jp |
| |
| Founder and CEO, Skinny Boy Associates |
| Mechanism Design and Social Engineering |
| REAL solutions to REAL problems of REAL people in REAL time! REALLY. |
| Phone: +81 (298) 56-2703 |
+-----------------------------------------------------------------------+
- Raw text -