Mail Archives: djgpp/1998/05/12/21:30:38
^Hawk^ wrote:
>
> On Tue, 12 May 1998 15:27:39 -0400, "John S. Fine"
> <johnfine AT erols DOT com> wrote:
>
> >at the end of a routine to restore registers and exit. For a
> >crash that occurs in that code, what better line number would
> >you like the compiler to have chosen than the line number of the
> >closing brace.
> Where the allocation fault was !?
It's not possible for the compiler to do that in any reasonable
fashion. C is very lenient; it lets you do almost anything on the
assumption that you meant to do it that way. There are some utilities
out there that allow you to track memory allocation and there are even
some that support runtime array bounds checking. However, the compiler
_can_ catch a great number of potential mistakes if you let it. The
'-Wall' and '-O' switches, when used in combination, can detect
variables that are potentially used without being initialized (among
other things).
Example code:
/* uninit.c */
#include <stdio.h>
int main( void )
{
char *p;
gets( p );
return 0;
}
When compiled with "gcc -Wall -O -g -o uninit.exe uninit.c", the
following warning occurs:
uninit.c: In function `main':
uninit.c:6: warning: `p' might be used uninitialized in this function
The problem is that too many people don't know about those incredibly
useful warning options.
If your problem was not allocating the correct _amount_ of memory for a
pointer, then there's no way or reason for the compiler to know that you
did anything wrong.
--
John M. Aldrich <fighteer AT cs DOT com> - ICQ UIN# 7406319
* Anything that happens, happens.
* Anything that, in happening, causes something else to happen,
causes something else to happen.
* Anything that, in happening, causes itself to happen again, happens
again.
* It doesn't necessarily do it in chronological order, though.
--- Douglas Adams
- Raw text -