Re: NULL and zeros



Eric Sosman wrote:
Yevgen Muntyan wrote:

Hey,

Are there not highly specialized and still existing and used platforms
where NULL is not a sequence of zeros, so that "char *a = NULL;" and
"char *a; memset (&a, 0, sizeof (a));" are not equivalent?

In other words, do I care about possible difference between NULL and
zero-filled pointer if e.g. I assume the target platform can run X
or it is Windows?


Have you read Question 5.17 in the comp.lang.c Frequently
Asked Questions (FAQ) list at <http://c-faq.com/>?

Also, have you read the tenth of the Ten Commandments for
C Programmers at <http://www.plethora.net/~seebs/c/10com.html>?

I have read those, and it's why I'm asking. Question is: is true
*hypothetical* portability more important than convenience in my
specific case?
For example, I do understand that it's silly to assume everything is 32-bits PC, but you should admit that it's quite reasonable to assume
that target win32 platform has sizeof(void*) == 32 (and I am not talking
about some code potentially ported to other platforms, no, code which
does HANDLE a = Blah()).

In my specific case, I am using glib and gtk libraries which assume
8-bits bytes and ASCII (i.e. will break on EBCDIC). And I do use
ASCII table when deal with characters (in a terminal emulator for
instance); sometimes I use 8 instead of sizeof(char); I even assume sometimes that int is at least 32 bits! Maybe it's
evil/bad/ignorant/kills kittens, but I am not going to stop using
ASCII table just because not everything is ASCII, since it simply
doesn't make sense in my setup.

It takes a tiny bit more effort to zero your pointers portably
than to just use calloc() or memset() and hope for the best -- but
the additional effort *is* tiny, after all!

It's lot of lines of obj->this = NULL; obj->that = NULL;
I get zero-initialized structures for free and would really love
not to have to initialize all pointers inside. Besides, lot of
NULL initializations makes code actually harder to modify - you need
to consult header to know whether you got all should-be-NULL actually
NULL's.

Best regards,
Yevgen
.



Relevant Pages

  • Re: NULL and zeros
    ... zero-filled pointer if e.g. ... 8-bits bytes and ASCII. ... characters; that's what character constants are for. ... of supported platforms all of which have 8-bits bytes? ...
    (comp.lang.c)
  • Re: NULL and zeros
    ... Are there not highly specialized and still existing and used platforms ... *hypothetical* portability more important than convenience in my ... 8-bits bytes and ASCII. ... not to have to initialize all pointers inside. ...
    (comp.lang.c)
  • Re: HeathField Strange Ideas!
    ... Presumably because there's no ASCII encoding for. ... For example, no, that's not the reason, because there's no ASCII ... ASCII-based platforms, ... rather more unportable than assuming ASCII, ...
    (comp.lang.c)
  • Re: Motif 1.3, Euro sign not standard ?!?
    ... The problem seems to be that the ascii value of the ... (euro if you can read it) ... is not standard on all platforms. ...
    (comp.os.vms)
  • Re: NULL and zeros
    ... Are there not highly specialized and still existing and used platforms ... not to have to initialize all pointers inside. ... the struct contains, ... like to initialize to "all members zero" (which may or may not be ...
    (comp.lang.c)

Quantcast