如何最好地提供模块 [英] How best to provide a module

查看:84
本文介绍了如何最好地提供模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在C中分发一段代码,最好如何提供它?

选项似乎是


1.预编译module.c文件到module.o并提供标题。

然后使用代码


#include" module.h"


位于顶部,需要与已编译的模块链接。


2.直接包含源代码。然后使用代码在最低词汇级别(即不在函数内)具有
#include" module.c"



这些可行的方法是否包含单独的源代码和

还有其他吗?


- -

TIA,

James

解决方案

James Harris说:
< blockquote class =post_quotes>
如果在C中分发一段代码,最好如何提供它?



这取决于你的需求。


期权似乎是


1.将module.c文件预编译到module.o并提供标题。

然后使用代码


#include" module.h"


位于顶部,需要与已编译的模块链接。



这是一种方式,如果您不想分发来源,它会很有用。


2.直接包含源代码。然后使用代码


#include" module.c"



但这不是*另一种方式! :-)至少,这是一个糟糕,糟糕的想法。如果

对于拥有源代码的用户来说没问题,只需向他们发送源代码

(无论如何你都必须这样做,以上为;工作"),或者依赖

给他们,或者告诉他们如何编译它并将它链接到他们的

项目中。 (你不应该告诉他们,除非他们对C很新。)


-

Richard Heathfield< http:/ /www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日


8月21日14:15,Richard Heathfield< r ... @ see.sig.invalidwrote:


James Harris说:



....


2.直接包含源代码。然后使用代码有


#include" module.c"



但这不是*另一种方式! :-)至少,这是一个糟糕,糟糕的想法。如果

对于拥有源代码的用户来说没问题,只需向他们发送源代码

(无论如何你都必须这样做,以上为;工作"),或者依赖

给他们,或者告诉他们如何编译它并将它链接到他们的

项目中。 (你不应该告诉他们,除非他们对C.很新。)



哈哈!我没见过有人这样做过。但为什么总是很糟糕?并且

有没有什么情况会好的?





詹姆斯哈里斯 < ja ************ @ googlemail.comwrote in message

news:cf ****************** **************** @ l42g2000 hsc.googlegroups.com ...


8月21日,14:15, Richard Heathfield< r ... @ see.sig.invalidwrote:


> James Harris说:



...


2.直接包含来源。然后使用代码有


#include" module.c"


但那不是*不是另一种方式! :-)至少,这是一个糟糕,糟糕的想法。如果用户有源,你就可以了,只需向他们发送消息来源
(无论如何你都必须这样做,为了上面的工作),要么依赖
对他们,或告诉他们如何,编译并将其链接到他们的
项目。 (你不应该告诉他们除非他们对C.很新。)



哈哈!我没见过有人这样做过。



我已经看过一两次了。


但为什么它总是很糟糕?



这会导致重复定义出现问题。




是有没有什么情况会好的?



永远不要说永远。 :-)


但我建议不要在没有引人注目的情况下这样做。

原因。

-Mike


If distributing a piece of code in C how is it best to provide it?
Options seem to be

1. Precompile the module.c file(s) to module.o and provide a header.
The using code then has

#include "module.h"

at the top and needs to be linked with the compiled module.

2. Include the source directly. The using code then has

#include "module.c"

at the lowest lexical level - i.e. not within a function. Are both of
these viable ways to include a separate piece of source code and and
are there any others?

--
TIA,
James

解决方案

James Harris said:

If distributing a piece of code in C how is it best to provide it?

It depends on your needs.

Options seem to be

1. Precompile the module.c file(s) to module.o and provide a header.
The using code then has

#include "module.h"

at the top and needs to be linked with the compiled module.

That''s one way, and it''s useful if you don''t want to distribute the source.

2. Include the source directly. The using code then has

#include "module.c"

But that''s *not* another way! :-) At least, it''s a lousy, lousy idea. If
you''re okay with the user having the source, just send them the source
(which you''d have to do anyway, for the above to "work"), and either rely
on them to, or tell them how to, compile it and link it into their
project. (You shouldn''t need to tell them unless they''re very new to C.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


On 21 Aug, 14:15, Richard Heathfield <r...@see.sig.invalidwrote:

James Harris said:

....

2. Include the source directly. The using code then has

#include "module.c"


But that''s *not* another way! :-) At least, it''s a lousy, lousy idea. If
you''re okay with the user having the source, just send them the source
(which you''d have to do anyway, for the above to "work"), and either rely
on them to, or tell them how to, compile it and link it into their
project. (You shouldn''t need to tell them unless they''re very new to C.)

Haha! I''ve not seen anyone do this. But why is it always lousy? And
are there no circumstances where it would be good?




"James Harris" <ja************@googlemail.comwrote in message
news:cf**********************************@l42g2000 hsc.googlegroups.com...

On 21 Aug, 14:15, Richard Heathfield <r...@see.sig.invalidwrote:

>James Harris said:

...

2. Include the source directly. The using code then has

#include "module.c"


But that''s *not* another way! :-) At least, it''s a lousy, lousy idea. If
you''re okay with the user having the source, just send them the source
(which you''d have to do anyway, for the above to "work"), and either rely
on them to, or tell them how to, compile it and link it into their
project. (You shouldn''t need to tell them unless they''re very new to C.)


Haha! I''ve not seen anyone do this.

I''ve seen it once or twice.

But why is it always lousy?

It can cause problems with duplicate definitions.

And
are there no circumstances where it would be good?

Never say never. :-)

But I recommend not to do it without some compelling
reason.

-Mike


这篇关于如何最好地提供模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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