You'd have to create a compiler, or modify an existing one, to use a
non-zero representation for null pointers. That's hardly "trivial".
(For example, default initialization for static objects could no
longer just zero the target object.)
I don't think there are any modern C compilers that don't use
all-bits-zero for null pointers. Other representations are of
course valid, but tend not to be worth the trouble.
I wouldn't be terribly surprised if a future standard mandated
all-bits-zero for null pointers -- or if it didn't.
On 28/07/2026 12:21, Johann 'Myrkraverk' Oskarsson wrote:
On 28/07/2026 6:22 PM, Keith Thompson wrote:
Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> writes:
On 28/07/2026 8:59 AM, Keith Thompson wrote:
Your ASCII art has nothing to do with the current discussion (and
didn't even display correctly due to line wrapping).˙ I've dropped
the cross-post to alt.ascii-art.˙ Can you please try to focus?
Nope.˙ You've absolutely demonstrated that you have no idea what
is involved in the internals of a C compiler.
You don't seem to have much idea either.
˙ What you're trying
to describe is just hogwash and balderdash when it comes to the
real world nitty gritty of implementing a compiler.
Now stay out of my compiler discussion, you're not wanted here!
Perhaps the rest of the group would be interested in knowing just
what I got so badly wrong.
I'll summarize it as: You think I care what the C standard documents
say.˙ I don't.
I care how it's implemented.˙ You don't.
This is what you wrote:
"I think more of it like an arm-chair thought exercise.˙ The issue
isn't the bit pattern at all, but how you're going to treat conversion
to integers.˙ Especially in this context,
˙ if ( p ) { ... }
a 64bit p with the pattern 0x..00000000 isn't supposed to be false,
when truncated to an integer...."
You don't say what type 'p' is, but I assume it is a pointer.
How a compiler implements this depends partly on what the language says,
for example:
˙ Scalar type˙ Value˙˙ True when
˙˙ integer˙˙˙˙˙ i˙˙˙˙˙ i != 0
˙˙ float˙˙˙˙˙˙˙ x˙˙˙˙˙ x != 0.0˙˙˙˙ (-0.0 may need considering)
˙˙ pointer˙˙˙˙˙ p˙˙˙˙˙ p != NULL
Whether NULL is all-bits-zero depends on the implementation, but I think
it it more platform-dependent rather than left to individual compilers.
Since in that case code from different compilers would be incompatible,
and calling into external libraries would be problematical.
In any case, there is no conversion to int involved; it is just has to implement that comparison by whatever means works.
On 28/07/2026 3:58 AM, Keith Thompson wrote:
You'd have to create a compiler, or modify an existing one, to use a
non-zero representation for null pointers. That's hardly "trivial".
(For example, default initialization for static objects could no
longer just zero the target object.)
__ .----.__
.________________________________________.
-' `/(#)#(#) `- . o O ( I tend to assume people are more
capable )
` (#)#(#) \ ___ ^( than they actually are, because
it )^^
__( \ ,,,/ `. ``. ( makes them either feel better,
or some- )
/ \ \,-/ | \ ( times they rise to the challenge!
)^^^^^^
| `-- ( ( /__ ( ^^^( )^^^^^^^^^^^^^^^^^^^^^^^^^^^^
` ( `---\ `---._` ( } (^^
^^)______________________________.
| | \ `----._`.`. .' ( For instance, this is an old
ASCII art )
. ( `-) \ `. )) ) | ( horror I made several years ago.
)^^^
/ \ / / ) / { ( I got semi-famous for my
collection )
/ \ / ( | ( ( of non-trivial ASCII art.
)^^^^^^^^^^
/ ,\ /\\\ ( |_ \ ( And I made all of it by hand,
including )
/ /\( ) / .`\\\ ^^( this thought bubble.
)^^^^^^^^^^^^^^
\\/ \ .-' | | -_ ^^^^^^^^^^^^^^^^^^^^^^^
\ .'___( ) \ `-.
-' \/\___\\__\
/** Do you ever mix C and ASCII art? **/
int main( int _, char *o[] ) { return _^( int ) main <3 ; }
I don't think there are any modern C compilers that don't use
all-bits-zero for null pointers. Other representations are of
course valid, but tend not to be worth the trouble.
I wouldn't be terribly surprised if a future standard mandated
all-bits-zero for null pointers -- or if it didn't.
I think more of it like an arm-chair thought exercise. The issue
isn't the bit pattern at all, but how you're going to treat conversion
to integers. Especially in this context,
if ( p ) { ... }
a 64bit p with the pattern 0x..00000000 isn't supposed to be false,
when truncated to an integer. If I remember the standard(s)
correctly, p here is supposed to "devolve" into either 1 or 0 in a
boolean context. I'd believe comparing to zero, and use the Z flag is
normal in x64, and in MIPS64, direct comparison to $zero is probably
the most normal way to go about it.
I forgot the actual instructions in both cases. They're easy to
look up anyway.
--
Johann | email: invalid -> com | http://www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | via Easynews.com
Pardon the top-posting. Just wanted to let you know that this
didn't display well on my particular setup, as my newsreading
software is set up to wrap at around 80 columns. IIRC this is
(or used to be at least) the accepted limit for line lengths.
Apologies. I did this in my text editor, and neglected to notice
the longest line is 81 columns. My editor says the end of the line
is at 80, but starts the column count at zero. I'm unsure if that
should be counted as 80 columns, or 81. Is the following any better
for you? The original displays correctly for me, in my newsreader.
__ .----.__ .________________________________________.
-' `/(#)#(#) `- . o O ( I tend to assume people are more
` (#)#(#) \ ___ ^( than they actually are, because it )^^
__( \ ,,,/ `. ``. ( makes them either feel better, or
/ \ \,-/ | \ ( times they rise to the challenge!
| `-- ( ( /__ ( ^^^( )^^^^^^^^^^^^^^^^^^^^^^^^^^^^
` ( `---\ `---._` ( } (^^
| | \ `----._`.`. .' ( For instance, this is an old ASCII
. ( `-) \ `. )) ) | ( horror I made several years ago.
/ \ / / ) / { ( I got semi-famous for my
/ \ / ( | ( ( of non-trivial ASCII art. )^^^^^^^^^^
/ ,\ /\\\ ( |_ \ ( And I made all of it by hand,
/ /\( ) / .`\\\ ^^( this thought bubble.
\\/ \ .-' | | -_ ^^^^^^^^^^^^^^^^^^^^^^^
\ .'___( ) \ `-.
-' \/\___\\__\
| Sysop: | Jacob Catayoc |
|---|---|
| Location: | Pasay City, Metro Manila, Philippines |
| Users: | 4 |
| Nodes: | 4 (0 / 4) |
| Uptime: | 496007:24:00 |
| Calls: | 178 |
| Files: | 605 |
| D/L today: |
7 files (18,398K bytes) |
| Messages: | 70,065 |