This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: problems with "clobbered" warnings
- To: Michael Richardson <mcr at solidum dot com>
- Subject: Re: problems with "clobbered" warnings
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Thu, 22 Jun 2000 15:12:02 -0700
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <200006222119.RAA17240@solidum.com>
On Thu, Jun 22, 2000 at 05:19:00PM -0400, Michael Richardson wrote:
>
> I am attempting to get some code to compile with -Wall -Werror. I have just
> introduced a setjmp() to catch errors...
>
> I get warnings like:
>
> paxas.c:211: warning: variable `infilename' might be clobbered by `longjmp' or `vfork'
...
>
> Is there someone who can offer a better description of when a variable may
> be considered to be clobbered, or a workaround that permits me to shut up
> just that test without giving up on the uninitialized warning?
The compiler generates those warnings for just about every variable in
a function that calls setjmp or vfork.
Your best option is not to use setjmp() at all. Have a
cleanup_and_exit() that cleans up and calls exit; mark it noreturn;
and call it directly whenever you would have called longjmp.
If that's not feasible for some reason, you may be able to structure
your code like this:
jmp_buf env;
int
main(void)
{
if(setjmp(env))
{
cleanup();
return 1;
}
do_all_the_real_work();
return 0;
}
- the key being to have no actual code in the routine that calls
setjmp, just function calls.
zw