This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.
See the CrossGCC FAQ for lots more information.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
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.
#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 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
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |