风格问题:#include [英] Style question: #include

查看:78
本文介绍了风格问题:#include的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用大型查找表的程序,在源代码中提供了一个大的

数组:


static int bigtbl [] = { 123,456,

/ *等等。* /

9999};


现在这个表很大,并且让我的主要来源混乱

文件非常难看。所以我想把它放在一个单独的文件中。

#include that。


样式问题是:如果单独的文件有一个。 c或.h

分机?有两个约定,我需要违反其中一个



1)#including .c文件很奇怪。

2把定义,而不仅仅是声明,放在.h文件中

也很奇怪。


想法?

I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I''d like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.

Thoughts?

推荐答案



也许你可以将它放在一个特殊的命名文件中,例如* bigtbl.data *。

Fr************@googlemail.com 写道:

Maybe you can put it in a special named file such as *bigtbl.data*.

Fr************@googlemail.com writes:

我有一个使用大型查找表的程序,在源代码中作为一个大的

数组提供:

static int bigtbl [] = {123,456,

/ *等等。* /

9999};

现在这个表非常大,让我的主要来源混乱

文件非常难看。所以我想把它放在一个单独的文件中。

#include that。


样式问题是:如果单独的文件有一个。 c或.h

分机?有两个约定,我需要违反其中一个



1)#including .c文件很奇怪。

2把定义,而不仅仅是声明,放在.h文件中

也很奇怪。


想法?
I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I''d like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.

Thoughts?



祝你好运

徐伟江

-

一切都有规则!

Best regards
Xu Weijiang
--
everything has its rules!




< Fr ************ @ googlemail.com写信息

新闻:11 *** *******************@d30g2000prg.googlegr oups.com ...

<Fr************@googlemail.comwrote in message
news:11**********************@d30g2000prg.googlegr oups.com...

>我有一个使用大型查找表的程序,在源代码中以大型

数组的形式提供:


static int bigtbl [] = {123,456,

/ *等等。* /

9999};


现在这张桌子非常大,让它变得杂乱无章主要来源

文件相当难看。所以我想把它放在一个单独的文件中。

#include that。


样式问题是:如果单独的文件有一个。 c或.h

分机?有两种惯例,我需要违反其中一个



1)#including .c文件很奇怪。
>I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I''d like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.



有些人可能称之为奇怪,有些则不称之为。但它完全有效。

有效。我会使用.c或其他一些扩展名

表示它是什么,也许.tbl

Some might call it weird, others not. But it''s perfectly
valid. I''d use either .c or some other extension which
indicates what it is, perhaps .tbl


2)定义一个定义在.h文件中,而不仅仅是声明,

也很奇怪。
2) putting a definition, rather than just declarations, in a .h file
is also weird.



与上述''怪异''相同的评论。在一个文件(无论其

名称)中,打算由多个其他文件#include包含

(''头文件的传统含义),它不会是
a好主意。


我在第三方图书馆看到过以下表格:

/ * \\ text.h * /

#define EXTERN extern

/ * array.h * /

EXTERN int array [SIZE];

/ * array.c * /

#define EXTERN

#include" array.h" / *''EXTERN''解析为空,所以定义发生* /

/ * otherfiles.c * /

#include ext.h

#include array.h / *导致extern声明* /

我真的不在乎这种方式,我可能会使用

之类的东西.tbl文件


-Mike

Same remarks about ''weird'' as above. In a file (whatever its
name) intended to be #included by more than one other file
(the traditional meaning of a ''header file), it would not be
a good idea.

I''ve also seen the following form in third party libraries I''ve used:
/* ext.h */
#define EXTERN extern
/* array.h */
EXTERN int array[SIZE];
/* array.c */
#define EXTERN
#include "array.h" /* ''EXTERN'' resolves to nothing, so definition occurs */
/* otherfiles.c */
#include ext.h
#include array.h /* causes extern declaration */
I don''t really care for that way, I''d probably use
something like a .tbl file

-Mike


Fr ************ @ googlemail.com 写道:

>

我有一个使用大型查找表的程序,在源代码中提供了一个大的

数组:


static int bigtbl [] = {123,456,

/ *等等。* /

9999};


现在这张桌子是非常大的,让它混乱我的主要来源

文件非常难看。所以我想把它放在一个单独的文件中。

#include that。


样式问题是:如果单独的文件有一个。 c或.h

分机?有两个约定,我需要违反其中一个



1)#including .c文件很奇怪。

2把定义,而不仅仅是声明,放在.h文件中

也很奇怪。


想法?
>
I have a program that uses a large lookup table, provided as a large
array in the source:

static int bigtbl[]={123, 456,
/* etc. etc. */
9999 };

Now this table is pretty big, and having it clutter up my main source
file is quite ugly. So I''d like to put it in a separate file and
#include that.

The style question is: should the separate file have a .c or .h
extension? There are two conventions, and I need to violate one of
them!
1) #including a .c file is weird.
2) putting a definition, rather than just declarations, in a .h file
is also weird.

Thoughts?



否,包括.c文件并不奇怪。作为一个.c文件,你是

警告不要#include它在多个来源(因为你通常可以

.h文件)。你也可以把它变成.d或.dat等文件,如果你想要的话。


-

< http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>

< http://www.securityfocus.com/columnists/423>

< http://www.aaxnet.com/editor/edit043.html>

cbfalconer at maineline dot net


-

通过 http://www.teranews.com上的免费Usenet帐户发布

No, including a .c file is NOT weird. Being a .c file, you are
warned not to #include it in multiple sources (as you normally can
a .h file). You could also make it a .d or .dat etc. file if you
wish.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com


这篇关于风格问题:#include的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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