473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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

Mar 29 '06 #1
12 1777
only when you include the file(in which static function is defined) in
another C file(in which you want to use)

Mar 29 '06 #2
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.

Mar 29 '06 #3
ji************@gmail.com 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

Mar 29 '06 #4
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.
Mar 29 '06 #5
ji************@gmail.com 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.

Mar 29 '06 #6
"jeniffer" <ze******************@gmail.com> 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) ks***@mib.org <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.
Mar 29 '06 #7
jjf

Vladimir S. Oka wrote:
ji************@gmail.com 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.

Mar 29 '06 #8

jj*@bcs.org.uk wrote:
Vladimir S. Oka wrote:
ji************@gmail.com 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

Mar 29 '06 #9
Keith Thompson wrote:
"jeniffer" <ze******************@gmail.com> 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.

Mar 29 '06 #10
"suresh" <ma**********@gmail.com> writes:
Keith Thompson wrote:
"jeniffer" <ze******************@gmail.com> 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.


Sure, there are real-world reasons to call a static function from a
different translation unit. But the way the question was phrased
leads me to suspect it's a homework question.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Mar 29 '06 #11
In article <11**********************@g10g2000cwb.googlegroups .com>,
jeniffer <ze******************@gmail.com> 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. The static declaration limits the scope of the function name,
but not that of the function itself.

-- Richard

Mar 29 '06 #12
On 2006-03-29, Martin Ambuhl <ma*****@earthlink.net> wrote:
ji************@gmail.com 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.


Yes, but a pointer-to-function being passed as a parameter is more
likely in the real world.
Mar 29 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.