This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is this safe

Is it safe to cast a null to struct just to get the size:

Example:

sizeof(((MEMORY_STRUCT*)0)->GWCD.sid)

Thanks
JD

Parents
  • says,

    "The sizeof operator yields the size (in bytes) of its operand, which may be an expression ... The size is determined from the type of the operand, which is not itself evaluated" (my emphasis).

    Which sounds like you should be safe?

    Presumably you were worried about the NULL pointer? I don't think that should be a problem - as the expression is not evaluated...?

Reply
  • says,

    "The sizeof operator yields the size (in bytes) of its operand, which may be an expression ... The size is determined from the type of the operand, which is not itself evaluated" (my emphasis).

    Which sounds like you should be safe?

    Presumably you were worried about the NULL pointer? I don't think that should be a problem - as the expression is not evaluated...?

Children