样式 - 嵌入数据文件 [英] Style - imbedding data files

查看:57
本文介绍了样式 - 嵌入数据文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,


通常的惯例是什么,通常和习惯的方式,

将数据文件包含在源文件中?


我有一些大型数据结构定义为源

类似于:


========== ===============

typedef struct fubar

{

unsigned int fab; / * something * /

unsigned int nrk; / * somethang * /

} Fubar;


静态Fubar myFubar [] =

{

{0x01,0x02},

{0x02,0x03},

/ *更多相同* /

{0x20,0x21 }

};

=========================


以上数据数组由单个

源文件使用。目前,它已被硬编码到源文件中,但是我需要将它移动到一个单独的文件中并包含它。

(实际情况实际上要多得多b $ b复杂多个大数据

数组,这些数据全部由相同的

单个源文件使用。)


将数据结构

定义放入.h中是否可以?头文件,甚至

虽然它只用于单个来源

文件?除了使用头文件之外,还有其他一些通常和习惯性的b $ b风格用于嵌入数据源吗?
定义?


数据数组仅以源

形式定义,而不是二进制文件等。


TIA


-

----------------------------

Jeffrey D. Smith

Farsight Systems Corporation

24 BURLINGTON DRIVE

LONGMONT,CO 80501-6906
http://www.farsight-systems.com

z / Debug调试你的系统在IBM z / OS上运行的/ C程序!

ISV升级费用是否过高?检查我们的定制产品开发!

解决方案

xarax写道:


通常的做法是什么,通常和习惯的方式,将数据文件包含在源文件中?

我有一些大型数据结构定义为源
类似于:


我建议如下:


---- FILE fubartype.h ----

#ifndef fubartype_h

#define fubartype_h typedef struct fubar
{unsigned int fab; / * something * /
unsigned int nrk; / * somethang * /
} Fubar;
#endif

----- EOF fubartype.h -----


----- FILE fubar.c - ---

#include" fubartype.h"

#include" fubar.h"静态Fubar myFubar [] =
{
{0x01,0x02},
{0x02,0x03},
/ *更多相同* /
{0x20 ,0x21}
};




/ *一些代码可以访问myFubar * /

/ *和fubar中的原型.h在别处使用* /

----- EOF fubar.c -----


和另一个文件fubar.h ;。


-

查克F(cb********@yahoo.com)(cb ******* *@worldnet.att.net)

可用于咨询/临时嵌入式和系统。

< http://cbfalconer.home.att.net>使用worldnet地址!


xarax写道:

问候,

一般做法是什么,通常和习惯的方式,将数据文件包含在源文件中?



[snip]


我总是喜欢第三种选择。

我更喜欢将数据放入汇编语言文件。

许多汇编语言可以更好地控制

的位置和属性数据。


我正在使用的汇编程序有一个包含

a二进制文件的指令。该语言允许我对齐数据

并将其放入只读段。棘手的部分

正在弄清楚如何在C中声明位置并且

访问它。


-

Thomas Matthews


C ++新闻组欢迎辞:
http://www.slack.net/~shiva/welcome.txt

C ++常见问题: http://www.parashift.com/c++-faq-lite

C常见问题: http://www.eskimo.com /〜scs/c-faq/top.html

alt.comp.lang.learn.c-c ++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html

其他网站:
http://www.josuttis.com - C ++ STL图书馆书


In< wb **************@newsread2.news.pas.earthlink.net> " xarax" < xa的*** @ email.com>写道:

将数据文件包含在源文件中的一般做法,通常和习惯的方式是什么?

我有一些定义为源的大型数据结构
类似于:

=========================
typedef struct fubar
{unsigned int fab; / * something * /
unsigned int nrk; / * somethang * /
} Fubar;

静态Fubar myFubar [] =
{
{0x01,0x02},
{0x02,0x03} ,
/ *更多相同* /
{0x20,0x21}
};
================= ========

上面的数据数组由单个源文件使用。目前,它已经硬编码到源文件中,但是我需要将它移动到一个单独的文件中并包含它。
(情况实际上要复杂得多)具有多个大数据
数组,这些数据全部由相同的单个源文件使用。)

将数据结构的定义放入/中是否正确? .H"头文件,甚至
虽然它只被单个源文件使用?


不。这不是一个头文件,因此你不会使用.h后缀。

是否还有一些其他通常和习惯性的样式来嵌入一个源代码数据
除了使用头文件之外的定义?


是的,你包含一个.c文件,其中包含你的数组的初始化。

数据数组只以源
形式定义,不是二进制文件或类似的东西。




这就是你为什么使用.c文件的原因。

头文件具有明确定义的目的,并且它不为您的阵列提供

初始化器。 OTOH,从另一个.c文件中包含一个.c

文件是完全可以的。在包含.c文件的

开头发表评论并没有什么坏处,解释说它应该是另一个文件所包含的
,而不是正如这样编译。


Dan

-

Dan Pop

DESY Zeuthen,RZ小组

电子邮件: Da*****@ifh.de


Greetings,

What is the general practice, usual and customary way,
of including a data file into a source file?

I have some large data structures defined as source
similar to:

=========================
typedef struct fubar
{
unsigned int fab; /* something */
unsigned int nrk; /* somethang */
} Fubar;

static Fubar myFubar[] =
{
{0x01,0x02},
{0x02,0x03},
/* much more of the same */
{0x20,0x21}
};
=========================

The above data array is used by a single
source file. Currently, it is hard-coded
into the source file, but I need to move
it into a separate file and include it.
(The situation is actually much more
complicated with multiple large data
arrays that are all used by the same
single source file.)

Is it alright to put that data structure
definition into a ".h" header file, even
though it is only used by a single source
file? Is there some other "usual and customary"
style for imbedding the source of a data
definition other than using a header file?

The data arrays are only defined in source
form, not binary files or such like.

TIA

--
----------------------------
Jeffrey D. Smith
Farsight Systems Corporation
24 BURLINGTON DRIVE
LONGMONT, CO 80501-6906
http://www.farsight-systems.com
z/Debug debugs your Systems/C programs running on IBM z/OS!
Are ISV upgrade fees too high? Check our custom product development!

解决方案

xarax wrote:


What is the general practice, usual and customary way,
of including a data file into a source file?

I have some large data structures defined as source
similar to:
I suggest the following:

---- FILE fubartype.h ----
#ifndef fubartype_h
#define fubartype_h typedef struct fubar
{
unsigned int fab; /* something */
unsigned int nrk; /* somethang */
} Fubar; #endif
----- EOF fubartype.h -----
----- FILE fubar.c ----
#include "fubartype.h"
#include "fubar.h" static Fubar myFubar[] =
{
{0x01,0x02},
{0x02,0x03},
/* much more of the same */
{0x20,0x21}
};



/* some code that provides access to myFubar */
/* and prototyped in fubar.h for use elsewhere */
----- EOF fubar.c -----

and a further file "fubar.h".

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


xarax wrote:

Greetings,

What is the general practice, usual and customary way,
of including a data file into a source file?


[snip]

I always like a third alternative.
I prefer to place data into an assembly language file.
Many assembly languages offer better control over the
location and attributes of the data.

The assembler I''m working with has a directive to include
a binary file. The language allows me to align the data
and place it into a read-only segment. The tricky part
is figuring out how to declare the location in C and
access it.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book


In <wb**************@newsread2.news.pas.earthlink.net > "xarax" <xa***@email.com> writes:

What is the general practice, usual and customary way,
of including a data file into a source file?

I have some large data structures defined as source
similar to:

=========================
typedef struct fubar
{
unsigned int fab; /* something */
unsigned int nrk; /* somethang */
} Fubar;

static Fubar myFubar[] =
{
{0x01,0x02},
{0x02,0x03},
/* much more of the same */
{0x20,0x21}
};
=========================

The above data array is used by a single
source file. Currently, it is hard-coded
into the source file, but I need to move
it into a separate file and include it.
(The situation is actually much more
complicated with multiple large data
arrays that are all used by the same
single source file.)

Is it alright to put that data structure
definition into a ".h" header file, even
though it is only used by a single source
file?
Nope. It''s not a header file, therefore you don''t use the .h suffix.
Is there some other "usual and customary"
style for imbedding the source of a data
definition other than using a header file?
Yes, you include a .c file, containing the initialiser for your array.
The data arrays are only defined in source
form, not binary files or such like.



That''s why you use a .c file for the purpose.

Header files have a well defined purpose and it isn''t providing
initialisers for your arrays. OTOH, it''s perfectly OK to include a .c
file from another .c file. It doesn''t harm to put a comment at the
beginning of the included .c file, explaining that it is supposed to be
included by another file, rather than being compiled as such.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de


这篇关于样式 - 嵌入数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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