This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Silently checking whether diagnostics would occur
- To: meissner at cygnus dot com
- Subject: Re: Silently checking whether diagnostics would occur
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Thu, 14 Sep 2000 11:30:49 -0400 (EDT)
- Cc: amylaar at cygnus dot co dot uk, gcc at gcc dot gnu dot org, gdr at codesourcery dot com
> From: Michael Meissner <meissner@cygnus.com>
>
> Rather than returning an error value, you could have the parameter be
> an int pointer, and if the pointer is NULL, otherwise set the pointer
> to non-zero and return. Another way to write the function is to pass
> a function that writes the error messages, and for the case you don't
> want the error messages, have it record in a static about being called
> and return, and change the other callers to pass error or what have
> you for the function.
One nit with passing in a function is that attribute printf doesn't
work on function pointers IIRC, so all the calls to the warning
function ptr would lose format checks. (Though I suppose that could
be fixed.) Sigh, that would have been cleaner since I could do
"#pragma poison warning" to make sure the function pointer parameter
was always used in preference to `warning'.
I'll look into passing in an int*, then I guess all calls to warning()
would instead be:
> if (foo)
> {*foo = 1; return;}
> else
> warning ("blah blah", arg1, arg2);
Although I appreciate now the reasons against using a global var, I
also see maintenance problems down the road ensuring that one always
uses the above idiom when adding new format checks.
Any ideas on making it more automatic and less dependent on good
behavior? Since `warning' is a varargs function, for portability
reasons I can't make the above snippet a macro.
Thanks,
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions