Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: Is there any way to make a function local to two TUs without including it as static in both? |
| Date | Tue, 10 Mar 2015 07:35:29 -0700 |
| Organization | None to speak of |
| Lines | 38 |
| Message-ID | <87d24g3opa.fsf@kst-u.example.com> (permalink) |
| References | <5bnrfahtskm5osi399eb9954bleglspe2k@4ax.com> <k6esfa9lkmb8ennqvvr7u03oo9oplrgg2u@4ax.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | mx02.eternal-september.org; posting-host="c77ff4d35e33d1c939d3461ebde8dd0d"; logging-data="12612"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+E+Y5hBvv346KQsUWXczC5" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:WJogiZiiEcbB+ZbTxZcD8Gkq1MU= sha1:HVsV3NV69IUGd84jkz4Er3vd9Kc= |
| Xref | csiph.com comp.lang.c:58054 |
Show key headers only | View raw
Robert Wessel <robertwessel2@yahoo.com> writes:
> On Mon, 09 Mar 2015 15:02:44 -0400, DSF <notavalid@address.here>
> wrote:
>>Is there any way to make a function local to two TUs without including
>>it as static in both?
>>
>> Note that this question is not "life or death." I can leave said
>>function in its own TU and declared public. I ask for reasons of
>>learning and "correctness." (The function need only be seen by the
>>two TUs, thus it would be logical for the symbol to be private to
>>them.)
>>
>> I have a function in its own TU that is used exclusively by two
>>other TUs. I know I can make it private by declaring it static within
>>the TUs and placing it in them, but then there would be two copies.
>
> You could give the common implementation a name unlikely to ever
> collide with anything, and then include a #define to translate that
> into something usable in the two modules actually using it.
What's the advantage of that over just declaring the function, with a
straightforward name, in a header that's #included only by the two
translation units that need it?
With the obscure name and the #define in a header, anything that
#includes the header can call the function. With a normal declaration
in a header, anything that #includes the header can call the function.
I think different people are making different assumptions about just
what hte OP means by "local". You can't make it entirely impossible for
something other than those two translation units to call the function.
The question is, just how difficult does it need to be?
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is there any way to make a function local to two TUs without including it as static in both? DSF <notavalid@address.here> - 2015-03-09 15:02 -0400
Re: Is there any way to make a function local to two TUs without including it as static in both? James Kuyper <jameskuyper@verizon.net> - 2015-03-09 15:22 -0400
Re: Is there any way to make a function local to two TUs without including it as static in both? Richard Heathfield <rjh@cpax.org.uk> - 2015-03-09 19:34 +0000
Re: Is there any way to make a function local to two TUs without including it as static in both? Keith Thompson <kst-u@mib.org> - 2015-03-09 12:47 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Richard Heathfield <rjh@cpax.org.uk> - 2015-03-09 21:33 +0000
Re: Is there any way to make a function local to two TUs without including it as static in both? Keith Thompson <kst-u@mib.org> - 2015-03-10 07:28 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Richard Heathfield <rjh@cpax.org.uk> - 2015-03-10 14:59 +0000
Re: Is there any way to make a function local to two TUs without including it as static in both? Keith Thompson <kst-u@mib.org> - 2015-03-10 10:37 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Richard Heathfield <rjh@cpax.org.uk> - 2015-03-10 18:45 +0000
Re: Is there any way to make a function local to two TUs without including it as static in both? Lőrinczy Zsigmond <nospam@for.me> - 2015-03-09 21:04 +0100
Re: Is there any way to make a function local to two TUs without including it as static in both? August Karlstrom <fusionfile@gmail.com> - 2015-03-09 21:39 +0100
Re: Is there any way to make a function local to two TUs without including it as static in both? Kaz Kylheku <kaz@kylheku.com> - 2015-03-09 21:20 +0000
Re: Is there any way to make a function local to two TUs without including it as static in both? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-09 19:23 -0500
Re: Is there any way to make a function local to two TUs without including it as static in both? wssimms@gmail.com - 2015-03-09 21:42 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-10 04:52 -0500
Re: Is there any way to make a function local to two TUs without including it as static in both? Keith Thompson <kst-u@mib.org> - 2015-03-10 07:35 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-10 12:53 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Les Cargill <lcargill99@comcast.com> - 2015-03-09 19:58 -0500
Re: Is there any way to make a function local to two TUs without including it as static in both? Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-24 13:06 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Les Cargill <lcargill99@comcast.com> - 2015-03-24 20:03 -0500
Re: Is there any way to make a function local to two TUs without including it as static in both? James Kuyper <jameskuyper@verizon.net> - 2015-03-25 10:26 -0400
Re: Is there any way to make a function local to two TUs without including it as static in both? Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-25 10:36 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Kaz Kylheku <kaz@kylheku.com> - 2015-03-25 17:47 +0000
Re: Is there any way to make a function local to two TUs without including it as static in both? Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-25 16:03 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-25 10:28 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Kaz Kylheku <kaz@kylheku.com> - 2015-03-25 17:46 +0000
[OT] Re: meaning of "signature" in other languages Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-25 16:01 -0700
Re: Is there any way to make a function local to two TUs without including it as static in both? Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-28 09:05 -0700
csiph-web