[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CC-mode indentation after macros

From: Star Watcher
Subject: Re: CC-mode indentation after macros
Date: Tue, 19 Oct 2004 20:15:58 +0200

If you're lucky enough to be using gcc's cpp preprocessor, I suggest you
take a look at its powerful "variadic macros" extensions.
Among other things, it will allow you to write elegant things like that:

#ifdef DEBUG
#define PRINTF(_X_,_ARGS_...)    printf(_X_,## _ARGS_)
#define PRINTF(_X_,_ARGS_...)    do{}while(0)

void foo(void)
  PRINTF("Debug print");

This will both avoid breaking cc-mode's indentation scheme AND make the code
look better (IMHO).
The do{}while(0) statement does not generate warnings with gcc -Wall, I
wonder if it fools lint also.
There are other C preprocessors that also support variadic macros... (see

"Ola Nilsson" <address@hidden> a écrit dans le message de
> Hello,
> I'm working with code that contains a number of debug
> macros. Typically the look like this:
> #ifdef DEBUG
> #define DEB(x) x
> #else
> #define DEB(x)
> #endif
> These are used in the code like this:
> void foo(void)
> {
>   ...
>   DEB(printf("Debug print";)
>   ...
> }
> That is, in many places the semicolon is inside the macro not outside
> (that would generate empty statements that lint would complain over).
> Now, my problem is that cc-mode wants to indent the next line, but I
> would like to have int on the same indentation level as the DEB
> line. How can I get this behaviour? Do I need to add regexps for the
> DEB() types of macros? And in that case, where should I add them?
> Thanks for any help,
> -- 
> /Ola Nilsson

reply via email to

[Prev in Thread] Current Thread [Next in Thread]