An Ubiquitous C bug

david nugent david at csource.oz.au
Tue Jan 22 14:36:54 AEST 1991


In <2831 at casbah.acns.nwu.edu> hpa at casbah.acns.nwu.edu (Peter Anvin) writes:

> >>This sort of program CAN print the message if x() happens to be
> >>loaded by the linker at the start of the code segment (address 0).

> All DOS compilers I know of use, in small-code models, the beginning of the
> code segment to store their startup code.

This is link order dependant; nothing whatever to do with the compiler.


> Thus, functions cannot be allocated to CS:0000h, and thus no 
> functions correspond to NULL.

Yes they can, and often are.


> The startup cod, which is written in assembler, sets up the stack, 
> local heap, floating point emulation and the arguments to main(), 
> as appropriate. main() just acts like a subroutine to the startup code.

... and can be wherever you like in the executable.


> Should NULL be all ones?

It, or an equivant, could be.

# define NULLFUNC	(int (*)()-1)


    david



More information about the Comp.lang.c mailing list