🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4991

Is it legal to add 0 to NULL? What about NULL < NULL?

#4991
From: Scott Mayo
Date: Sat, 06 Apr 1996 15:02
18 lines
1014 bytes
I ask because a standard trick for walking an array A of size S is:

Thing *a = A;
Thing *fence = a + S;
for (; a < fence; ++a)
    /* use a */;

but in my case, if S happens to be 0, a will start out NULL. This makes we
worry about both the value of fence, and, if that works, the behaviour
of (a < fence), which I hope is (NULL < NULL), which I hope the standard
blesses as reliably false, but I have this feeling that it won't.

I know I can use int i; for (i = 0; i < S; ++i) but I was
hoping to avoid the extra math at array dereference time. I know
I can preface the whole thing with if (a != NULL) but the fun of
a standard is knowing what you can get away with. :)

Comments?
Technical Details
Message-ID: <ff1d.smail.smayo@tiac.net>
Path: arc1-ca.pugleaf.net!news.tiac.net!smayo

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.tiac.net!smayo
From: smayo@tiac.net (Scott Mayo)
Newsgroups: comp.std.c
Subject: Is it legal to add 0 to NULL? What about NULL < NULL?
Date: Sat, 06 Apr 1996 10:02:08 -0500
Organization: The Internet Access Company
Message-ID: <ff1d.smail.smayo@tiac.net>
NNTP-Posting-Host: sunspot.tiac.net