CopyPastor

Detecting plagiarism made easy.

Score: 0.8002553582191467; Reported for: String similarity Open both answers

Original Post

Original - Posted on 2014-10-21
by Ben Voigt



            
Present in both answers; Present only in the new answer; Present only in the old answer;

No. In fact, no null pointer constant is a null pointer! This is because constants and pointers are different kinds of entities.
A null pointer constant is a constant ***expression*** which has a particular form. An expression is a sequence of tokens, and null pointer constants are defined as sequences of tokens that have a particular form.
A null pointer is a ***value***. In C, each type has its set of potential values. For each pointer type, one or more value in that set is a null pointer. The C standard does not define the concept of value formally. A formal semantics would need to do this (and formally defining values of pointers gets rather complicated, which is why the C standard, an English document written without mathematics, doesn't try).
An expression ***evaluates*** to a value in a context (possibly causing side effects). All null pointer constants whose type is a pointer type evaluate to a null pointer. Some null pointer constants (e.g. `0`, `1L - 'z' / 'z'`) have an integer type, and those do not evaluate to a null pointer: they evaluate to a null integer (i.e. an integer with the value 0 — the C standard does not use the expression “null integer” because it isn't anything remarkable that would need a specific name).
It is a parenthesized expression which contains a null pointer constant, so it indisputably is a null pointer value. Using it as an rvalue has exactly the same effect as using the "compliant" version as an r-value.
If there were some syntactic rules that could *only* accept a null pointer constant, it would not qualify. But I'm not aware of any (though I'm less expert on C).
And while neither one is a *constant* (referring to the formal grammar production), both can appear in a constant expression in an initializer, because both null pointer constants and address constants are allowed, and a constant null pointer value is explicitly included in the category of *address constant*.
Pointer comparisons also specifically mention null pointer constants... but here pointer values are also accepted, and all null pointer values are treated equally. Same for the ternary and assignment operators.
Please do be aware that these rules are quite different in C++, where both the above expressions are constant null pointer values of type `void*`, but not universal null pointer constants. Null pointer constants in C++ are **integral constant expressions** which evaluate to zero. And `void*` doesn't implicitly convert to other pointer types.

        
Present in both answers; Present only in the new answer; Present only in the old answer;