Monday 15 April 2013

c++ - What's the point of g++ -Wreorder? -


In the + + + + + + + + -Wall option, this option is described below, it is not clear to me why someone cares (Especially, enough to turn it on by default - Wall).

 -Wreorder (C ++ only) Warn when the code given in the code is not the order of initializers, in which the order should be executed. For example: struct A {int i; Int j; A (): J (0), i (1) {}}; In order to match the announcement order of compiler members, the member will reorganize the initiators and emit the warning for that effect. By this warning -Wall is enabled 

Consider:

  Struct a {int i; Int j; A (): J (0), I (j) {}};  

Now i is started in some unknown value, not zero.

Alternatively, i can have some side effects for which order is important. E.g.

  A (int n): j (n ++), i (n ++) {}  

No comments:

Post a Comment