build-crossgcc.sh for gcc3.2.3?
Dan Kegel
dank@kegel.com
Wed May 7 16:57:00 GMT 2003
Bill Gatliff wrote:
> Dan:
>
>> Plus, it's nice to be able to use attributes on function pointers :-)
>
> Ooh, do tell! Got an example or two?
Sure. I have a logging system that lets users pass me a function
pointer for use as the log destination. Users then log errors
by doing something like
DPRINT("the %d is %s\n", id, status_str);
which expands to
(*dprint_fn)(__LINE__, __FILE__, __FUNCTION__, "the %d is %s\n", id, status_str);
With older compilers, I can't mark that global function pointer with
the attributes needed to catch format string mismatches, so use
of DPRINT ends up riskier than using printf. With newer gcc's,
I can give that nice typechecking by adding
__attribute__((format (printf, 5, 6)))
in front of the pointer declaration.
BTW, to make this compile on older gcc's, I wrap attribute in a macro:
#define __GCC_VERSION(major,minor,patchlevel) (((major)*10000)+(minor*100)+(patchlevel))
#define __GCCV __GCC_VERSION(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
#if defined(__GNUC__) && (__GCCV >= __GCC_VERSION(3,2,0))
#define attribute(...) __attribute__(__VA_ARGS__)
#else
#define attribute(...)
#endif
- Dan
--
Dan Kegel
http://www.kegel.com
http://counter.li.org/cgi-bin/runscript/display-person.cgi?user=78045
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com
More information about the crossgcc
mailing list