Home
| Calendar
| Mail Lists
| List Archives
| Desktop SIG
| Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU |
At some point hitherto, Frank Ramsay hath spake thusly: > I'm horrible with Macros in C does anyone know how to make a macro > that w ? > Now I have a ton of these so altering them manually would take much > longer than I have. Does anyone know of a macro or function that > takes var args for printf and re-formats them to a more logfile > friendly format? Well, I'm not exactly sure what you're looking for, but I've written functions and macros that do something that sounds similar. They take a format string, followed by variable arguments, and use them to create a message to send to syslog(). The function that does the logging is declared as such: /* log a standard log message with the given priority */ void log_msg( int priority, char *msg, ... ); Then I have two macros that use this function, defined like this: #define error_msg( format, args... ) log_msg( LOG_ERR, format, ##args ) #define debug_msg( format, args... ) log_msg( LOG_DEBUG, format, ##args ) The log_msg() function uses vnsprintf() to stick all the args in a suitable buffer, ? la: /* stuff for variable arg list */ va_start( arg_item, msg ); vsnprintf( buff, ( length + MAX_MSG_LEN ), msg, arg_item ); va_end( arg_item ); If that's not what you're looking for, it should at least illustrate how to do what you're trying to do. FYI, this (the macro stuff, that is) is documented in an obscure part of the Gnu C preprocessor documentation. It may be a Gnu-specific extension... I haven't been able to find any other place (i.e. text books) where this feature is described. -- Derek Martin ddm at pizzashack.org --------------------------------------------- I prefer mail encrypted with PGP/GPG! GnuPG Key ID: 0x81CFE75D Retrieve my public key at http://pgp.mit.edu Learn more about it at http://www.gnupg.org -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 232 bytes Desc: not available URL: <http://lists.blu.org/pipermail/discuss/attachments/20020616/f82fa31f/attachment.sig>
BLU is a member of BostonUserGroups | |
We also thank MIT for the use of their facilities. |