* CC-mode indentation after macros
@ 2004-10-19 7:59 Ola Nilsson
2004-10-19 18:15 ` Star Watcher
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ola Nilsson @ 2004-10-19 7:59 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: CC-mode indentation after macros
2004-10-19 7:59 CC-mode indentation after macros Ola Nilsson
@ 2004-10-19 18:15 ` Star Watcher
2004-10-19 19:22 ` Ola Nilsson
2004-10-19 20:04 ` Stefan Monnier
2 siblings, 0 replies; 4+ messages in thread
From: Star Watcher @ 2004-10-19 18:15 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1579 bytes --]
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_)
#else
#define PRINTF(_X_,_ARGS_...) do{}while(0)
#endif
/*...*/
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
manual)
--
Laurent
"Ola Nilsson" <sds024five1@sydpost.nospam.nu> a écrit dans le message de
news:87oeiz16lf.fsf@helmut.nilsson.homedns.org...
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: CC-mode indentation after macros
2004-10-19 7:59 CC-mode indentation after macros Ola Nilsson
2004-10-19 18:15 ` Star Watcher
@ 2004-10-19 19:22 ` Ola Nilsson
2004-10-19 20:04 ` Stefan Monnier
2 siblings, 0 replies; 4+ messages in thread
From: Ola Nilsson @ 2004-10-19 19:22 UTC (permalink / raw)
Ola Nilsson <sds024five1@sydpost.nospam.nu> writes:
> 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?
First, thanks Laurent for your reply. Unfortunately I'm not useing GCC
for the code described. If it was only my project, I would easily
adopt your suggestion.
I seem to have found something that works for me, the statement-cont
indentation configuration. So far it seems to do what I want. I added:
(c-set-offset 'statement-cont 0)
to my c-mode hook. Now the line after the DEB macro get's indented
like I want. There is probably some draw back that I've not yet found,
but so far so good.
And I got to try the lisp debugger and debug-on-entry ;-)
Again, thanks!
--
/Ola Nilsson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: CC-mode indentation after macros
2004-10-19 7:59 CC-mode indentation after macros Ola Nilsson
2004-10-19 18:15 ` Star Watcher
2004-10-19 19:22 ` Ola Nilsson
@ 2004-10-19 20:04 ` Stefan Monnier
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2004-10-19 20:04 UTC (permalink / raw)
> #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).
Then run lint with DEBUG enabled so the statements aren't empty.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-10-19 20:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-19 7:59 CC-mode indentation after macros Ola Nilsson
2004-10-19 18:15 ` Star Watcher
2004-10-19 19:22 ` Ola Nilsson
2004-10-19 20:04 ` Stefan Monnier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).