use of NULL

Don_A_Corbitt at cup.portal.com Don_A_Corbitt at cup.portal.com
Thu Feb 23 04:09:17 AEST 1989


Clayton,
  Counter example time for MSC and NULL.  (We already know of many counter 
examples for other machines, such as Pyramid...)

Compact model (data pointer 32 bit, function pointer 16 bit).

Function that has a function pointer argument called if error occurs (or calls 
exit() if no error handler passed in...)

void DoSomething(int p1, int p2, void (*errhand)(int));

(oops - make this medium model - 32 bit code pointer, 16 bit data)

Call DoSomething with no function prototype:
  (and no error handler)
  DoSomething(100, 200, NULL);

NULL is defined as 0 (16 bits).  DoSomething detects an error, checks the
errhand parameter, it is not 0 (32 bits), so it calls the function.  If you 
cast NULL to a function pointer, it will pass a 32 bit pointer, and all is
well.
	Don_A_Corbitt at cup.portal.com



More information about the Comp.lang.c mailing list