On Wed Oct 22, 2003 at 18:39:07 +1000, Tiwari, Rajnish wrote:
>Hi All,
>
>       I am stuck trying to decide on 2 courses of action - one
>       of which involves changes to loads of files (I wish to avoid
>       doing this if possible).
>
>       Currently, I have this C-function:
>       int DEBUG(char* xstr, int somelevel)
>       { 
>         // pseudo-pseudo-code follows
>         if ( somelevel < 10 )
>              print xstr;
>
>         return 0;
>       }
>
>       char* fs(const char* fmt, ...);
>
>       And they are used as follows (as an example):
>       DEBUG( fs("%s%s", "-----", "====="), 25 );
>
>
>       I aim to deprecate the use of fs() - as you will see the call to
>       fs() is wasted its output isn't being printed. I aim to shove down
>       that responsibility to DEBUG itself.
>
>       My Question:
>       Is it possible to do use C-processor macros to define fs() to
>       _become_ nothing, and call my new DEBUG with the follow prototype:
>       int NEW_DEBUG(int somelevel, const char* fmt, ...);     ??
>
>       That is:
>       #define fs(msg,...) ??????     // leaves me with just "msg,..."

I'm sure I answered this question, or a similar a couple of days ago, but

#define fs(msg...) msg

>       #define DEBUG(const char*, ... , level) NEW_DEBUG(level, const
>char*, ????)

Um, I'm not sure what you want to do here. Your old DEBUG was:

DEBUG(char*, level), not DEBUG(const char*, ..., level)

Of course the latter is impossible, you can't have variadic arguments in
the middle of your function definition.

Instead of a solution, I'll point you to the wonerful manual:

http://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html,

which is kind of hard to find if you don't realise these things are
called variadic macros. (And even then if you can't spell like me, you
still have trouble).

Benno
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

Reply via email to