said:
> Hi,
>
> Is there any way, by which we can limit a specific function to be
> called
> only from a specific function ? I dont know the advantage of this.
> Someone
> asked this question from me in an interview.
>
> thanks for any help ...
For ease of reference, let's call them foo() and bar(), and you want it to
be impossible to call bar() except from foo().
Put foo() and bar() in foo.c. Make bar() static:
static int bar(double *, void ***, char, unsigned long);
Compile foo.c to an object file, and publish the object file, together with
the interface spec (foo.h, which need not and indeed should not even
mention bar() at all), to your users. Don't give them the source file.
They don't need it, and it'd only get them poking around in the guts of
bar(), which is presumably what you're trying to prevent.
Provided you do not export bar()'s address from foo() - and if you don't
know what I'm talking about, it's extremely unlikely that you'd do this by
accident! - then you will now only be able to call bar() from foo().
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.