(C question) (s - out.s) + func(&out) -> ?
William Park
opengeometry-FFYn/CNdgSA at public.gmane.org
Thu Oct 31 03:50:14 UTC 2013
Question for C expert... Given the following
char *s;
struct { char *s; } out;
char *func();
s = (s - out.s) + func (&out);
where 'out' is changed inside function 'func'. What I want is
- to calculate (s - out.s) first, then
- add that difference to pointer returning from func().
Here, order is important, because func() changes 'out'.
However, gcc is doing
s = func (&out) + (s - out.s);
Is pointer arithmetic always done as
(pointer) + (int)
even if I write
(int) + (pointer)
?
PS. Of course, using intermediate variable solves the problem. But, my
understanding is that '+' is left-to-right precedence.
--
William
--
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