Re: NULL and zeros
- From: Yevgen Muntyan <muntyan.removethis@xxxxxxxx>
- Date: Tue, 03 Oct 2006 03:56:35 GMT
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
.
- Follow-Ups:
- Re: NULL and zeros
- From: Eric Sosman
- Re: NULL and zeros
- From: Keith Thompson
- Re: NULL and zeros
- From: Peter Nilsson
- Re: NULL and zeros
- From: Barry Schwarz
- Re: NULL and zeros
- References:
- NULL and zeros
- From: Yevgen Muntyan
- Re: NULL and zeros
- From: Eric Sosman
- NULL and zeros
- Prev by Date: Re: NULL and zeros
- Next by Date: Re: standard libraries
- Previous by thread: Re: NULL and zeros
- Next by thread: Re: NULL and zeros
- Index(es):
Relevant Pages
|