|C compiler warning messages? firstname.lastname@example.org (1997-04-06)|
|Re: C compiler warning messages? email@example.com (1997-04-07)|
|Proactive Compiler Error Messages firstname.lastname@example.org (Christopher Glaeser) (1997-04-08)|
|Re: C compiler warning messages? morris@CAM.ORG (1997-04-08)|
|Re: C compiler warning messages? email@example.com (David Chase) (1997-04-11)|
|Re: C compiler warning messages? firstname.lastname@example.org (1997-04-16)|
|Re: C compiler warning messages? morris@CAM.ORG (Morris Bernstein) (1997-04-16)|
|[1 later articles]|
|From:||email@example.com (John Roberts)|
|Date:||6 Apr 1997 22:30:14 -0400|
|Organization:||Integrated Measurement Systems, Inc.|
|Keywords:||storage, errors, practice|
I ran into a situation in some C code where I think the compiler
could've helped me out with some intelligent warning messages, but
I'm running under Solaris 2.5 using the stock Sun compilers.
The situation was a function like this:
return (char *)&rstr;
(Fortunately I didn't write this code!)
Anyway the problem with the above fragment is that rstr is on the
stack and can get reclaimed at any time. This was generating
intermittent errors during execution of the program, sometimes fun()
would return the correct string, sometimes not.
The solution I used was to declare char rstr using "static", which
solved the problem.
However, in general, it seems to me that the C compiler should of
given me a warning about returning a pointer to a string about to go
out of scope.
Anyone else out there have any experience with warning messages? Can
compilers detect this situation? Are there any other compilers
(e.g. GNU) that would give a warning on this?
[GCC 2.x does indeed produce a warning. Do compilers commonly diagnose
this bug? And remember, with a proper garbage collected storage model,
this wouldn't be a bug! -John]
Return to the
Search the comp.compilers archives again.