Difference between "identical pointer type" and "… / void* / null"

In Table 2, the remarks sometimes mention that the pointer types must be identical (or void* or null). I thought that “void*” would work with any other pointer, e.g. testing if a pointer is greater than null is the equivalent to “… != NULL”. Is this not the case?

  1. When void* or null is not explicitly mentioned, does this mean that this is not valid?
  2. Does identical mean that the types are the same (e.g. int is not identical to char) or implicitly convertible (e.g. int <> char, but int <!> char*)?
  • identical means identical. int* is not convertible to char*.

  • when void* and null are not explicitly mentioned, then they are not valid. This is because -, <, >, <= and >= all require size information for the type that the pointer points to, which void* and null do not have.

1 Like

by == or != of binaryExpression, char*/int*/void* == 0 is valid?
if so, how can I check if the right Expression from the binaryExpression is 0…
should i just use this.getRight.toString == “0”? or this.getRight == null??

this.getRight.toString == “0”

You would probably want to use .equals and pick the right string, but this could work. However, I would not do this.

this.getRight == null

This would mean that the right hand side does not exist, which should not happen. It’s certainly not what you want.

Instead, I would recommend putting a method like isNullConstant or similar in your Expression class.
You can even have it return false by default, and you only need to overwrite that for integer constants.

Of course, other options are also possible.

1 Like

alles Klar, thanks very much :+1: