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 10 1358
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
James Harris wrote:
Haha! I've not seen anyone do this. But why is it always lousy?
Because it means, that you can include that module into only one
source file. If you include it multiple times, that you got a
bunch of object files all with the same identifiers clashing at
link time.
And are there no circumstances where it would be good?
No. Either provide a separate header, or just provide the source
file and let the other people extract a header with a bunch of
PERL code.
Wolfgang Draxinger
--
E-Mail address works, Jabber: he******@jabber.org, ICQ: 134682867
"Wolfgang Draxinger" <wd********@darkstargames.dewrote in message
James Harris wrote:
>Haha! I've not seen anyone do this. But why is it always lousy?
Because it means, that you can include that module into only one
source file. If you include it multiple times, that you got a
bunch of object files all with the same identifiers clashing at
link time.
Simply make all the functions and globals static.
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm
On 21 Aug, 15:25, "Mike Wahler" <mkwah...@mkwahler.netwrote:
....
But why is it always lousy?
It can cause problems with duplicate definitions.
ok
And
are there no circumstances where it would be good?
Never say never. :-)
But I recommend not to do it without some compelling
reason.
Agreed.
Malcolm McLean wrote:
>
"Wolfgang Draxinger" <wd********@darkstargames.dewrote in message
>James Harris wrote:
>>Haha! I've not seen anyone do this. But why is it always lousy?
Because it means, that you can include that module into only one source file. If you include it multiple times, that you got a bunch of object files all with the same identifiers clashing at link time.
Simply make all the functions and globals static.
Reduces the problem a bit, but does not solve it. To be sure,
it can't be solved completely: Name collisions are ultimately
unavoidable when integrating C code from multiple suppliers.
However, separate compilation has the virtue of limiting the
"exposed" identifiers to those with external linkage, the module's
public interface, more or less. Wholesale source inclusion, on the
other hand, brings *all* the module's identifiers out into the open
where they can collide with the user's names.
/* module.c */
void doThis(void) { ... }
void doThat(void) { ... }
static void helper(void) { ... }
The normal approach requires the rest of the program to avoid using
`doThis' and `doThat' as externally-linked identifiers. Wholesale
inclusion requires the including module to avoid `doThis' and
`doThat' *and* `helper' for *any* file-scope identifiers.
Also, the mention of "globals" suggests that the consequences
have not been thought through. If `static int global;' appears in
the #include'd module, then each translation unit that #includes it
gets its very own private version of `global'. If Module M1 sets
`global = 42;', Module M2 cannot detect it -- which sort of goes
against the purpose of having a "global" in the first place.
-- Er*********@sun.com
James Harris <ja************@googlemail.comwrites:
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.
That can work, but only if the module.o file is compatible with the
user's system. You could provide multiple versions of module.o for
different systems. It's a pain, but it's pretty much necessary if you
don't want to distribute your source code.
You might also consider distributing shrouded C source. There are
utilities that will automatically obfuscate C source code, so it will
still compile and have the same semantics but is practically very
difficult to read or modify.
But if you don't mind distributing your sources (and your second idea
suggests you don't), then you probably shouldn't bother.
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?
Bad idea. Just distribute two files, module.h and module.c.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
"James Harris" <ja************@googlemail.comwrote in message
news:95**********************************@2g2000hs n.googlegroups.com...
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?
3. Precompile into a dynamic library. Distribute the library plus a .h file
or docs sufficient to make use of the library.
The format will vary between OSs, but is not so dependent on compiler (or,
to some extent, language).
--
Bartc
James Harris wrote:
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?
It may allow some compilers to perform better optimization (such as
inlining) if the entire program is presented as a single translation unit.
S This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Matthew Wilson |
last post by:
Hi-
I'm writing a bunch of classes, several of which need functions and
variables defined in the math module. In some instances, I'm going to
import my module like this:
import myshapes
...
|
by: dananrg |
last post by:
I'm a little confused about what's out there for database modules at:
http://python.org/topics/database/modules.html
What I'd like to do is use Python to access an Oracle 9.X database for...
|
by: Rudy |
last post by:
Hello All!
I'm a little confused on Public Class or Modules.
Say I have a this on form "A"
Public Sub Subtract()
Dim Invoice As Decimal
Dim Wage As Decimal
Static PO As Decimal
Invoice =...
|
by: Thomas Ploch |
last post by:
Hello fellows,
I just wanted to know, if there is any best practice concerning
following code:
import re, shelve
class TextMatcher:
def __init__(self, patterns, email=False,...
|
by: André |
last post by:
Hi,
i'm developping asp.net applications and therefore i use VB.net. I have some
questions about best practises.
According what i read about class and module and if i understand it right, a...
|
by: Sells, Fred |
last post by:
I need to talk to a vendor side via SOAP, Googling is overwhelming and many
hits seem to point to older attempts.
Can someone tell me which SOAP module is recommended. I'm using Python 2.4.
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |