Messages in this thread | | | Date | Wed, 20 May 1998 14:48:42 -0400 (EDT) | From | "Richard B. Johnson" <> | Subject | Re: 'C' Operators precedence |
| |
On Wed, 20 May 1998, Matthew Kirkwood wrote:
> On Wed, 20 May 1998, Richard B. Johnson wrote: > > And this _without_ optimisation. gcc is right to do this; if a function > clobbers registers, then let it do so when the variables don't contain > anything interersting anyway. > > Your point was..? >
Sigh. It has nothing to do with clobbering registers. It has to do with the fact that the function(s) and/or macros, anything that closes (), will all be 'evaluated' first. To evaluate a function, requires that any parameters passed to the function be stabilized by a sequence-point, and the function be called. To evaluate a macro, requires only that it be expanded as text. However, the () for passed parameters to a macro, if it exists, requires that the contents of () be evaluated before the macro is expanded, because () has the highest presedence of any 'C' operator.
#include <stdio.h>
static int a, b, c, d, e; static int f() { return a; } int main() { b = 1; c = 2; d = 3; e = 4; printf("%d\n", f() + b + c + d + e ); printf("%d\n", b + f() + c + d + e ); printf("%d\n", b + c + f() + d + e ); printf("%d\n", b + c + d + e + f() ); return 0;
}
Compile this with -S. This will show that the function is always called first, regardless of where it is first seen by the compiler. It must do this because of the reasons previously stated.
Cheers, Dick Johnson ***** FILE SYSTEM MODIFIED ***** Penguin : Linux version 2.1.101 on an i586 machine (66.15 BogoMips). Warning : It's hard to remain at the trailing edge of technology.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu
| |