Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Can a static function defined in a C file be ever referred (called) externally ?

Reply
Thread Tools

Can a static function defined in a C file be ever referred (called) externally ?

 
 
jeniffer
Guest
Posts: n/a
 
      03-29-2006
Can a static function defined in a C file be ever referred (called)
externally from another C file?If so in which conditions?

 
Reply With Quote
 
 
 
 
jitu.csewizard@gmail.com
Guest
Posts: n/a
 
      03-29-2006
only when you include the file(in which static function is defined) in
another C file(in which you want to use)

 
Reply With Quote
 
 
 
 
Vladimir S. Oka
Guest
Posts: n/a
 
      03-29-2006
jeniffer opined:

> Can a static function defined in a C file be ever referred (called)
> externally from another C file?If so in which conditions?


Yes, if you declare a variable to be a pointer to such a function, and
make it point to that function (obviously this has to be done in the
file where `static` function is). If that pointer is not static, it
can be used from elsewhere to call that function.

It may help if you think of function /names/, they're not accessible.

--
BR, Vladimir

INTOXICATED:
When you feel sophisticated without being able to pronounce it.

 
Reply With Quote
 
Vladimir S. Oka
Guest
Posts: n/a
 
      03-29-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) opined:

> only when you include the file(in which static function is defined)
> in another C file(in which you want to use)


What are you talking about? Who are you talking to? Read:

<http://cfaj.freeshell.org/google/>
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Also, your answer is wrong. Including a file into another makes it a
part of that file, and thus irrelevant to the original question. See
my other post for the correct answer.

--
BR, Vladimir

"I know not with what weapons World War III will be fought, but World
War IV will be fought with sticks and stones."
-- Albert Einstein

 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      03-29-2006
jeniffer wrote:
> Can a static function defined in a C file be ever referred (called)
> externally from another C file?If so in which conditions?


Yes. Through a pointer-to-function that has been assigned the address
of the static function. The pointer must have external linkage and the
assignment done in the compilation unit containing the static function.

This allows a compilation unit to have several candidate static
functions and a function which can choose which one is to be used.


 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      03-29-2006
(E-Mail Removed) wrote:
> only when you include the file(in which static function is defined) in
> another C file(in which you want to use)


This is incorrect. A pointer-to-function with external linkage will do
the job.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-29-2006
"jeniffer" <(E-Mail Removed)> writes:
> Can a static function defined in a C file be ever referred (called)
> externally from another C file?If so in which conditions?


Is this a homework question?

If you want to call a function from another C file, don't make it
static.

(That doesn't answer your original question.)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
jjf@bcs.org.uk
Guest
Posts: n/a
 
      03-29-2006

Vladimir S. Oka wrote:
> (E-Mail Removed) opined:
> > jeniffer wrote:
> > > Can a static function defined in a C file be ever referred (called)
> > > externally from another C file?If so in which conditions?

> >
> > only when you include the file(in which static function is defined)
> > in another C file(in which you want to use)

>
> your answer is wrong. Including a file into another makes it a
> part of that file, and thus irrelevant to the original question. See
> my other post for the correct answer.


No, it's still a separate file but it becomes part of the same
translation unit. The information is correct, but it's not the "only"
way.

 
Reply With Quote
 
Vladimir S. Oka
Guest
Posts: n/a
 
      03-29-2006

(E-Mail Removed) wrote:
> Vladimir S. Oka wrote:
> > (E-Mail Removed) opined:
> > > jeniffer wrote:
> > > > Can a static function defined in a C file be ever referred (called)
> > > > externally from another C file?If so in which conditions?
> > >
> > > only when you include the file(in which static function is defined)
> > > in another C file(in which you want to use)

> >
> > your answer is wrong. Including a file into another makes it a
> > part of that file, and thus irrelevant to the original question. See
> > my other post for the correct answer.

>
> No, it's still a separate file but it becomes part of the same
> translation unit. The information is correct, but it's not the "only"
> way.


Re-read the OP above.

--
BR, Vladimir

 
Reply With Quote
 
suresh
Guest
Posts: n/a
 
      03-29-2006
Keith Thompson wrote:
> "jeniffer" <(E-Mail Removed)> writes:
> > Can a static function defined in a C file be ever referred (called)
> > externally from another C file?If so in which conditions?

>
> Is this a homework question?
>
> If you want to call a function from another C file, don't make it
> static.
>


This situation is not just academic. Consider a callback function
implementation.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function call fail to external script referred by page loaded with Ajax lovecreatesbeauty Javascript 2 07-20-2011 10:18 AM
Finding the file referred to in a Python traceback metaperl.etc@gmail.com Python 1 09-28-2006 03:12 PM
Externally-defined properties? Terry Hancock Python 3 08-25-2005 08:23 AM
Printing a file to a printer &/or changing the device that is referred to by stdout Jody Burgess Python 2 07-17-2004 04:59 AM
Where can I get the dll referred to in this msdn article? Michael Tholkes ASP .Net 2 06-30-2003 11:10 AM



Advertisments