(C question) (s - out.s) + func(&out) -> ?
Lennart Sorensen
lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Tue Nov 5 18:06:39 UTC 2013
On Thu, Oct 31, 2013 at 11:40:20AM -0400, D. Hugh Redelmeier wrote:
> | From: William Park <opengeometry-FFYn/CNdgSA at public.gmane.org>
>
> | Question for C expert... Given the following
>
> The order of operation is well-defined in C: operator precedence.
>
> That says nothing about the order of evaluation of operands, only
> about how they are combined.
>
> Your code has a race condition and is undefined by the C standard.
Functions calls are evaluated before addition/subtraction. That's in
the standard. Since the function modifies the parameter, the value
changes before the addition work is done.
Relying on the order variables are read into registers in a given C
statement is generally a bad idea. Just don't do it. Don't use and
modify a value in the same statement either. The outcome is often
undefined so that the compiler is free to do whatever is most efficient.
--
Len Sorensen
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list