I've given up here and I'm starting over with a clean new question
Let me try to rephrase the question as objectively and simply as possible:
I want someone to either give me a list of platforms (or answer that there are no such platforms) that is both ANSI C conforming and for which the following C program would print 0
:
#include <string.h>
#include <stdio.h>
struct MyStruct {
void *somePointer;
};
int main() {
struct MyStruct ms;
memset(&ms, 0, sizeof(ms));
printf("%d\n", ms.somePointer == 0);
}
ORIGINAL QUESTION:
Consider the following:
struct MyStruct {
void *somePointer;
};
int main() {
struct MyStruct ms;
memset(&ms, 0, sizeof(ms));
/* Can I assume ms.somePointer == NULL here? */
}
My understanding from posts about null pointers such as this one and this one is that the actual bytes in memory representing a null pointer may be non-zero, even though you could substitute the 0
literal for NULL
in source.
In particular, my understanding from the linked posts is that it is possible in ANSI C (C89, C99 or any of the other rervisions) to have ms.somePointer != NULL
on some platforms (please correct me if I'm wrong about this).
I have two questions about this:
- Are there any real platforms for which I will actually observe
ms.somePointer != NULL
? - If such platforms exist, how common are these platforms? Could I have a few examples?
EDIT:
To clarify, this question is related, but is not asking the same question.
The linked question is asking about when NULL
used to be some nonzero literal, presumably pre-ANSI C.
This question is asking: when I can assume I am working with an ANSI C standards compliant environment where NULL
really is interchangeable with 0
constant literal at the source level, are there any platforms/environments that have non-zero representations for null pointers in memory.