c++ - void *p...; if (p > 0) .... Is this undefined behavior? -


After a compiler upgrade I received a new warning message.

WARNING: Command to compare pointer with integer zero [[VIDEO]

  if (inx> gt; 0)    

An indicator that comes out is usually I expect this old code to be 0 or less. It has got me to think about signed and unsigned values ​​and possible risk.

Some research shows:

  • <
  • It suggests that an address (returned by malloc) can never be zero

    which is my old copy of standard.

    4.10 pointer conversion

    1 single tap indicator constant is an integral static expression (5.1 9) integer type property which evaluates zero A private std :: nullptr_t type or a null pointer constant can be changed into an indicator type; The result is the empty indicator value of that type and separates the object or pointer from the other type of function into the work type. This type of conversion is called a zero-pointer conversion. Compare two similar types of null pointer values. A null pointer constant is an indicator of conversion from an indicator to a CV-quality ad type, rather than an index conversion sequence that happens after the Quillin Quarter Conversions (4.4). The redundant indicator of an integral type can be changed into a type of continuous type: std :: nullptr_t

    It specifically states that the comparison of two tap signals is the same.

    Keeping this in mind, is this small piece of code undefined? Or is there another piece of puzzle I am missing?

    This is not an undefined behavior, but the result is unspecified if inx is not zero.

    C ++ 11 5.9 / 2: If two points point to the P and the same type of different objects, for the same object or element of the same array or for various functions , Or if only one of them is empty , p < q , P & gt; q , p < = q , and p & gt; = q Unspecified .

    You can make sure that if the conditional code does not execute, if inx is zero - but it will not be that it is not zero. It is possible to compare inx! = 0 , which is well defined if and only if inx is non-empty.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -