Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!rutgers!uwvax!umn-d-ub!umn-cs!randy From: randy@umn-cs.CS.UMN.EDU (Randy Orrison) Newsgroups: comp.os.minix Subject: Re: Minix/ST problems. Summary: solution: ALWAYS cast NULL in function calls Message-ID: <9847@umn-cs.CS.UMN.EDU> Date: 1 Nov 88 16:41:19 GMT References: <249@cstw01.UUCP> <7683@boring.cwi.nl> <486@midgard.UUCP> Reply-To: randy@cctb.mn.org (Randy Orrison) Organization: Chemical Computer Thinking Battery, St. Paul, MN Lines: 55 In article <486@midgard.UUCP> dal@syntel.UUCP (Dale Schumacher) writes: |In article <7683@boring.cwi.nl> siebren@cwi.nl (Siebren van der Zee) writes: ||In article <249@cstw01.UUCP> meulenbr@cstw01.UUCP writes: ||>Hi! ||>I've encountered a number of problems using Minix/ST . ||>The major problem is that it defines NULL as 0. THIS IS NOT A PROBLEM. ||>This is a killer on an ST since sizeof(char *) == 32 and sizeof(int) == 16. ||>Solution: change the 0 in (char *)0 SOLUTION: cast NULL in function calls |The X3J11 C standard proposal discusses this problem. It states that NULL |may be defined as 0, 0L or ((void *) 0) as needed by an implementation. |Therefore, is makes sense for NULL to be 0 (maybe) on the PC version, and |0L on the ST. If used properly, the definition of NULL is irrelevant. In the context of an assignment or comparison, the compiler can figure out the appropriate type and will do the cast for you. In the context of a parameter to a function, there is NO DEFINITION that will work universally, and so it MUST BE CAST to the appropriate type. (Exception: In ANSI C, function prototypes will allow the compiler to figure out the type and do the cast for you. (in which case the definition again doesn't matter.)) |Other liberties, like assuming sizeof(int)==sizeof(char *) |and failing to declare pointer return values, are simply NON-PORTABLE and |should not be used in Minix-related code or anything else pretending to be |portable. I think it is very desirable to have code which compiles under |Minix-PC work properly under Minix-ST with NO CHANGES, and visa-versa. I |don't think this is unreasonable to expect. Agreed, whole heartedly. |P.S.: When we get a more ansi-conformal compiler for Minix, possibly from |Sozobon, NULL would change to the ((void *) 0) that it SHOULD be. This really doesn't matter... Summary: For any definition of NULL, and any foo_type or mumble: foo_type *a; a = NULL; /* IS portable */ if (a == NULL) /* IS portable */ my_func (NULL); /* is NOT portable (unless there's a prototype) */ my_func ((mumble *)NULL); /* IS portable, and REQUIRED for portability under pre-ANSI C */ -- Randy Orrison, Chemical Computer Thinking Battery -- randy@cctb.mn.org (aka randy@{ux.acss.umn.edu, umn-cs.uucp, umnacca.bitnet, halcdc.uucp}) If you think last Tuesday was a drag, wait till you see what happens tomorrow!