pBuf[i++] = Calc(pBuf, i);

S

Sven K?hne

Hello *,

Our new compiler has some problems with this line:

pBuf[i++] = Calc(pBuf, i);

The Assembler-Code generated uses the increases "i" as a Paramter in
Calc. Our old Compiler did not do this. So who is right.

And where is the lay (ANSI-C Definition) written ans available, that
says ist is rigth, and this is wrong?

Thanks, Sven
 
J

Jonas

Sven K?hne said:
Hello *,

Our new compiler has some problems with this line:

pBuf[i++] = Calc(pBuf, i);

Order of evaluation is unspecified in above expression (it is actually an
undefined statement). So you should not write code like that.
The Assembler-Code generated uses the increases "i" as a Paramter in
Calc. Our old Compiler did not do this. So who is right.

Both or none! (see above)
 
M

Mark McIntyre

Our new compiler has some problems with this line:

pBuf[i++] = Calc(pBuf, i);

The Assembler-Code generated uses the increases "i" as a Paramter in
Calc. Our old Compiler did not do this. So who is right.

Probably neither. See section 3.1 of the FAQ.

You'll need to rewrite the expression so that it gives you the answer
you want without relying on undefined behaviour .
And where is the lay (ANSI-C Definition) written ans available, that
says ist is rigth, and this is wrong?

ISO C standard 6.5.2
Between the previous and next sequence point an object shall have its
stored value modified at most once by the evaluation of an expression.
Furthermore, the prior value shall be read only to determine the value
to be stored.

I believe that in the above expression, you are reading it once to
determine the value to store, and once to pass to a function, and you
also modify it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,065
Members
48,770
Latest member
ElysaD

Latest Threads

Top