9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] creating a library, simple question
@ 2004-08-20 10:15 Alberto Cortes
  2004-08-20 15:23 ` Francisco Ballesteros
  2004-08-20 16:10 ` Charles Forsyth
  0 siblings, 2 replies; 5+ messages in thread
From: Alberto Cortes @ 2004-08-20 10:15 UTC (permalink / raw)
  To: 9fans

i am trying to create a library, the source files looks like this:

term% ls
me_util.c
me_util.h
mevents.c
mevents.h
mkfile
term% cat mkfile
< /$objtype/mkfile

LIB=libmevents.a$O

OFILES=\
	mevents.$O\
	me_util.$O\

HFILES=\
	mevents.h\
	me_util.h\

</sys/src/cmd/mklib


"me_util.c" defines some helper functions for my library and...
"me_util.h" declares them.
"mevents.c" defines the functions to be served by the library.
"mevents.h" is the header file to be included by other programs, its only
declares the functions defined in "mevents.c", not the ones in "me_util.c".

How do i prevent other programs that include "mevents.h" and are
linked to my library, from seeing the functions in "me_utils.c"?

Additional explanation:
"me_util.c" declares a "void error(char *s)" function, but other
programs would want to use functions called "error" for sure. How do i
prevent the two "error" functions from collision?

i have seen some libraries with the underscore solution:

void
_error(char *s)

is it a good solution to prevent name collision?





--
http://montoya.aig.uc3m.es/~acortes/index.html


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] creating a library, simple question
  2004-08-20 10:15 [9fans] creating a library, simple question Alberto Cortes
@ 2004-08-20 15:23 ` Francisco Ballesteros
  2004-08-20 16:10 ` Charles Forsyth
  1 sibling, 0 replies; 5+ messages in thread
From: Francisco Ballesteros @ 2004-08-20 15:23 UTC (permalink / raw)
  To: Alberto Cortes, Fans of the OS Plan 9 from Bell Labs

just keep your tools separate in the header and add
a /* internal use only */ comment to that section.
You have examples in some of the libraries, see /sys/src.

If the symbols are extern, nobody can prevent others from using them.

hth

On Fri, 20 Aug 2004 12:15:29 +0200, Alberto Cortes <alcortes@coitt.es> wrote:
> i am trying to create a library, the source files looks like this:
>
> term% ls
> me_util.c
> me_util.h
> mevents.c
> mevents.h
> mkfile
> term% cat mkfile
> < /$objtype/mkfile
>
> LIB=libmevents.a$O
>
> OFILES=\
>         mevents.$O\
>         me_util.$O\
>
> HFILES=\
>         mevents.h\
>         me_util.h\
>
> </sys/src/cmd/mklib
>
> "me_util.c" defines some helper functions for my library and...
> "me_util.h" declares them.
> "mevents.c" defines the functions to be served by the library.
> "mevents.h" is the header file to be included by other programs, its only
> declares the functions defined in "mevents.c", not the ones in "me_util.c".
>
> How do i prevent other programs that include "mevents.h" and are
> linked to my library, from seeing the functions in "me_utils.c"?
>
> Additional explanation:
> "me_util.c" declares a "void error(char *s)" function, but other
> programs would want to use functions called "error" for sure. How do i
> prevent the two "error" functions from collision?
>
> i have seen some libraries with the underscore solution:
>
> void
> _error(char *s)
>
> is it a good solution to prevent name collision?
>
> --
> http://montoya.aig.uc3m.es/~acortes/index.html
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] creating a library, simple question
  2004-08-20 10:15 [9fans] creating a library, simple question Alberto Cortes
  2004-08-20 15:23 ` Francisco Ballesteros
@ 2004-08-20 16:10 ` Charles Forsyth
  2004-08-20 17:20   ` Alberto Cortes
  1 sibling, 1 reply; 5+ messages in thread
From: Charles Forsyth @ 2004-08-20 16:10 UTC (permalink / raw)
  To: alcortes, 9fans

with C the usual solution is to give the functions a short prefix
(dbmopen, dbmstore, regcomp, regexec, ndbsearch) or be
in a position to set the standard for everyone else
my clash is your fault.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [9fans] creating a library, simple question
  2004-08-20 16:10 ` Charles Forsyth
@ 2004-08-20 17:20   ` Alberto Cortes
  2004-08-20 18:43     ` boyd, rounin
  0 siblings, 1 reply; 5+ messages in thread
From: Alberto Cortes @ 2004-08-20 17:20 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Fri, 20 Aug 2004 17:10:29 +0000, Charles Forsyth wrote:
> with C the usual solution is to give the functions a short prefix
> (dbmopen, dbmstore, regcomp, regexec, ndbsearch) or be
> in a position to set the standard for everyone else
> my clash is your fault.
>
------ end of the original message ------

thanks for the advice, i will use a prefix and also include an
"internal use only" comment on the headers, as nemo suggested.

It is a pity; at first i created a single file with all the functions,
the helper ones declared as "static". But i decided to split it by
virtue of readability :-(


--
http://montoya.aig.uc3m.es/~acortes/index.html


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] creating a library, simple question
  2004-08-20 17:20   ` Alberto Cortes
@ 2004-08-20 18:43     ` boyd, rounin
  0 siblings, 0 replies; 5+ messages in thread
From: boyd, rounin @ 2004-08-20 18:43 UTC (permalink / raw)
  To: Alberto Cortes, Fans of the OS Plan 9 from Bell Labs

> thanks for the advice, i will use a prefix and also include an
> "internal use only" comment on the headers, as nemo suggested.

sounds like a bad idea.  use static or restructure.

or limbo ...



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-08-20 18:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-20 10:15 [9fans] creating a library, simple question Alberto Cortes
2004-08-20 15:23 ` Francisco Ballesteros
2004-08-20 16:10 ` Charles Forsyth
2004-08-20 17:20   ` Alberto Cortes
2004-08-20 18:43     ` boyd, rounin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).