Tuesday 15 September 2015

C++ Perincrement Undefined Operation vs C -



C++ Perincrement Undefined Operation vs C -

i have line of code:

front = (++front) % size;

in c no warnings in c++ warning operation on front end may undefined [-wsequence-point]. how preincrement usage cause undefined behavior? in mind, line unambiguous , interpreted as:

increment front mod front end size assign new value front.

is compiler throwing blanket warning?

p.s. understand warning if doing front = front++; or heaven forbid front = front++ + front++;.

edit: warning produced in codeblocks on windows 64 using gcc (tdm-1) 4.6.1

the old sequencing rules had border cases order of operations defined still technically undefined behavior. c++11 , c11 has been fixed replacing sequence point requirements 'sequenced-before' , 'sequenced-after' relations.

your illustration happens such case. if you're getting warnings in c11 or c++11 mode warning hasn't been updated new rules yet. in before c , c++ modes warning correct. if you're not getting warnings in before modes weren't implemented, , that's okay 'no diagnostic required'.

at same time, line can written more , right under old rules:

front = (front + 1) % size;

c++

No comments:

Post a Comment