Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!hao!oddjob!gargoyle!att-ih!ihnp4!inuxc!iuvax!silver!backstro From: backstro@silver.bacs.indiana.edu (Dave White) Newsgroups: comp.lang.c Subject: Re: nasty evil pointers Message-ID: <1159@silver.bacs.indiana.edu> Date: 10 Mar 88 00:46:25 GMT References: <13100003@bucc2> Reply-To: backstro@silver.UUCP (Dave White) Organization: Indiana University BACS, Bloomington Lines: 37 Summary: You need explicit heap size control In article <13100003@bucc2> brian@bucc2.UUCP writes: > >It would be nice if we could check every pointer as >it was used... > > >If pointer >pointed, say, into the operating system or the text space, the function >would print a message and exit(). Otherwise it would return. > >Without source to the compiler it could >be a major project. Does anybody know a way this could be done, perhaps with >something like lex? > Lattice C 3.0 (and, I suppose, more recent versions) allow the size of the stack and the size of the heap to be specified at runtime -- one uses an argument of the form =ssize/heapsize which the runtime startup routine digests before calling main(). Given such a beast, Lattice can provide isxxxx() functions that determine whether a passed pointer points within an expected space. However, the programmer must call them explicitly. This makes it possible to determine when a wild pointer endangers the machine. It has the disadvantage that the proper heapsize might need to be fudged, as well as the stacksize.... developing code for 8086's anf friends is painful enough... The sanest way to do what you want automatically is to build it into the compiler itself. Because compilers frequently call internal functions not made available to the user, and because of the difficulty of cases like the one you mention, it just isn't practical to write a pre-processor for this -- you'd be halfway to rewriting the compiler! >--- > When the going gets weird, the weird turn pro. No, they just bring out an Optimizing Turbo 5.0 version :-) -- backstro@silver.bacs.indiana.edu