Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!bloom-beacon!bu-cs!dartvax!libdev!ericb From: ericb@libdev (Eric Bivona) Newsgroups: comp.lang.c Subject: pointers, tests, casts Message-ID: <11130@dartvax.Dartmouth.EDU> Date: 22 Nov 88 21:44:45 GMT Sender: news@dartvax.Dartmouth.EDU Reply-To: Eric.J.Bivona@Dartmouth.EDU Organization: Dartmouth College, Hanover, NH Lines: 27 I have a question about tests on pointers, w.r.t. the ANSI standard for C. I know about casting NULL or 0 to get an appropriate nil pointer to test against: char *ptr; void *malloc(); ptr = (char *)malloc(256); /* or (size_t)256? ;-) */ if (ptr == (char *)0) { /* or (char *)NULL */ perror("malloc"); exit(1); } In assignments, a 0 or NULL is cast implicitly to the correct pointer type (I think, please correct me if I'm wrong). What about the '==' comparison above? Would "(ptr == 0)" get evaluated correctly? Or to push it a bit further, what about the VAX-ish standard (like *(char *)0 = 0 ;-) "(!ptr)"? I realize that it is probably better to explicitly cast & compare, but it did kind of make sense to say "if (!ptr)..." Thanks in advance, -Eric Bivona DCIS Project, Dartmouth College