Need some examples

Mark Galassi rosalia at tekig4.UUCP
Wed Aug 7 01:35:14 AEST 1985


In article <299 at brl-tgr.ARPA> you write:
>
>    There are a variety of funny little problems with using the 0
>pointer in C.  Recently I have gotten into a debate with a friend
>about passing a 0 pointer to a function.  We agree that given
>a function declaration like
>
>f(ptr)
>foo *ptr;
>{
>	[code]
>}
>
>calling f(0) is dangerous.  But my friend contends that calling
>f() with a zero char pointer, e.g. f((char *)0), is safe, because
>(char *) is the largest pointer, and that he doesn't know of a C
>implementation that doesn't pass all pointers as the largest
>possible pointer (ala the way floats always get passed as doubles).

    There is a problem: when you work with the Intel 80286
in large models instead of small ones **(for those who have never
worked with this misfit of nature, the 80286 cannot use more than
64K of memory unless you do some bank switching, which is such a pain
in the neck that one usually tries to use the small model of program
in which you only make use of 64K)**, you have to be careful because
pointers are 32 bits in large model, and 16 bits in small model.
    This is a horrible situation because you cannot even trust to
do "#define NULL 0L", because that will not work in small model
and you will have garbage on the stack. On the other hand
"#define NULL 0" will not work for the large model. The only
solution is to cast things properly with (char *), but then
you have to compile all your libraries twice, once with the large
model C compiler and once with the small one.
    So much for that, and the chains of the past (4004) weigh
heavilly upon us programmers, while the salesmen are always happy
to talk about how the segments "enable portability of software".

				Mark Galassi
			...!tektronix!tekig4!rosalia
			...!tektronix!reed!rosalia



More information about the Comp.lang.c mailing list