缩进C预处理程序指令 [英] Indent C preprocessor directives

查看:74
本文介绍了缩进C预处理程序指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以推荐一个程序来缩进C预处理器

指令。我的文件看起来像这样:

#ifdef a

#define b

#else

#define c

#endif


int main()

{

返回0;

}

我想要一个程序能够自动缩进预处理器

指令。


我已经尝试过astyle ,但没有成功。


Bogdan

解决方案

Bogdan写道:


任何人都可以推荐一个程序来缩进C预处理器

指令。我的文件看起来像这样:

#ifdef a

#define b

#else

#define c

#endif


int main()

{

返回0;

}

我想要一个程序能够自动缩进预处理器

指令。


我已经尝试过astyle但是没有成功。



缩进(1)和vim都说你提供的来源已经很好地缩进了
...


如果您想要的是类似的东西


#ifdef a

#define b

#else

#define c

#endif


,那我觉得你''我的习惯很不寻常......


Bogdan



-

Pietro Cerutti


PGP公钥:
http://gahr.ch/pgp

2007年5月21日,Pietro Cerutti< ga ** @ gahr.chwrote:


Bogdan写道:
< blockquote class =post_quotes>
>任何人都可以推荐一个程序来缩进C预处理程序
指令。我的文件看起来像这样:
#ifdef a
#define b
#else
#define c
#endif

int main( )
{
返回0;
}
我想要一个程序能够自动缩进预处理器
指令。

我已经尝试了astyle,但没有成功。



缩进(1)和vim都说你提供的来源已经是

缩进了好方法...


如果您想要的是类似的东西


#ifdef a

#定义b

#else

#define c

#endif


,那么我想你'有一个不寻常的习惯......



也许不寻常,但至少*我不再感到如此孤独; - )

我觉得有些编译器很久以前就不支持预处理器

指令#除了第一列以外的其他指令,但没有我支持
在过去的几年中使用的
有这个资源triction。说真的,不是
缩进的子句版本*方式*更容易阅读?如果我们缩进如果

条款,为什么我们不能因为同样的原因缩进#if条款?


BTW,我不会使用单独的程序。我的编辑器使用它的自动功能处理大部分




Dave


- -

David Tiktin

tiktin [at] advancedrelay [dot] com


David Tiktin写道:


>

2007年5月21日,Pietro Cerutti< ga ** @ gahr.chwrote:


Bogdan写道:


任何人都可以推荐一个程序来缩进C预处理器

指令。我的文件看起来像这样:

#ifdef a

#define b

#else

#define c

#endif



[...]


我希望程序能够自动缩进预处理器

指令。



[...]


如果你想要的东西类似于这个


#ifdef a

#define b

#else

#define c

#endif


,那么我觉得你有一个不寻常的习惯......



也许不寻常,但至少*我不再感到如此孤独;-)


我认为一些编译器很长之前没有支持预处理器

指令与第一列中的#以外的其他指令,但是在过去几年里我没有使用过
指令。



我看过程序在第一列中保留''#'',并在它和指令之间插入

空格。 (标准是否允许这是允许的吗?)使用相同的例子:


#ifdef a

#define b

#else

#define c

#endif


说真的,isn '缩进的子句版本*方式*更容易阅读?

如果我们缩进if子句,为什么我们不能缩进#if子句为

同样的原因?



当你有复杂的嵌套#if / #ifdef'时,对我来说肯定更容易

。但是,我编程的时间足够长,以至于我已经使用了第1列中需要''#'的编译器,并且没有空白

跟着它所以我养成了不缩进这些东西的习惯。

如果标准保证上述两种情况之一,我可能会自行重新培训



[...]


-

+ -------------- ----------- + -------------------- + ----------------- ------ +

| Kenneth J. Brody | www.hvcomputer.com | #include |

| kenbrody / at\spamcop.net | www.fptech.com | < std_disclaimer.h |

+ ------------------------- + --------- ----------- + ----------------------- +

不要 - 邮寄给我:< mailto:Th ************* @ gmail.com>


Can anyone recommend a program for indentation of C preprocessor
directives. My file looks like this:
#ifdef a
#define b
#else
#define c
#endif

int main()
{
return 0;
}
and I want a program able to automatically indent the preprocessor
directives.

I have already tried astyle, but with no success.

Bogdan

解决方案

Bogdan wrote:

Can anyone recommend a program for indentation of C preprocessor
directives. My file looks like this:
#ifdef a
#define b
#else
#define c
#endif

int main()
{
return 0;
}
and I want a program able to automatically indent the preprocessor
directives.

I have already tried astyle, but with no success.

indent(1) and vim both say that the source you provided is already
indented in a good way...

If what you want is something similar to this

#ifdef a
#define b
#else
#define c
#endif

, then I think you''ve got quite an unusual habit...

Bogdan


--
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp


On 21 May 2007, Pietro Cerutti <ga**@gahr.chwrote:

Bogdan wrote:

>Can anyone recommend a program for indentation of C preprocessor
directives. My file looks like this:
#ifdef a
#define b
#else
#define c
#endif

int main()
{
return 0;
}
and I want a program able to automatically indent the preprocessor
directives.

I have already tried astyle, but with no success.

indent(1) and vim both say that the source you provided is already
indented in a good way...

If what you want is something similar to this

#ifdef a
#define b
#else
#define c
#endif

, then I think you''ve got quite an unusual habit...

Maybe unusual, but at least *I* don''t feel so lonely anymore ;-)

I think some compilers long ago didn''t support preprocessor
directives with the # other than in the first column, but none I''ve
used in that past few years have that restriction. Seriously, isn''t
the indented clause version *way* easier to read? If we indent if
clauses, why shouldn''t we indent #if clauses for the same reason?

BTW, I don''t use a separate program for this. My editor handles most
of it for me with it''s autoindent feature.

Dave

--
D.a.v.i.d T.i.k.t.i.n
t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m


David Tiktin wrote:

>
On 21 May 2007, Pietro Cerutti <ga**@gahr.chwrote:

Bogdan wrote:

Can anyone recommend a program for indentation of C preprocessor
directives. My file looks like this:
#ifdef a
#define b
#else
#define c
#endif

[...]

and I want a program able to automatically indent the preprocessor
directives.

[...]

If what you want is something similar to this

#ifdef a
#define b
#else
#define c
#endif

, then I think you''ve got quite an unusual habit...


Maybe unusual, but at least *I* don''t feel so lonely anymore ;-)

I think some compilers long ago didn''t support preprocessor
directives with the # other than in the first column, but none I''ve
used in that past few years have that restriction.

I''ve seen programs keep the ''#'' in the first column, and insert
whitespace between it and the directive. (Does the Standard say
that this is allowed?) Using the same example:

#ifdef a
# define b
#else
# define c
#endif

Seriously, isn''t the indented clause version *way* easier to read?
If we indent if clauses, why shouldn''t we indent #if clauses for the
same reason?

When you have complex nested #if/#ifdef''s, it is certainly easier
to read for me. However, I''ve been programming long enough that I''ve
used compilers that required the ''#'' in column 1, and no whitespace
following it, so I got in the habit of not indenting such things.
If the Standard guarantees both/either of the above, I just may
retrain myself.

[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>


这篇关于缩进C预处理程序指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆