Can a static function defined in a C file be ever referred (called)
externally from another C file?If so in which conditions? 12 1798
only when you include the file(in which static function is defined) in
another C file(in which you want to use)
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. 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
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. 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.
"jeniffer" <ze************ ******@gmail.co m> 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_Keit h) 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.
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. 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
Keith Thompson wrote: "jeniffer" <ze************ ******@gmail.co m> 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 webserver runs that part of the
script (see attached file, snippet.php), though, it doesn't go through.
I don't get an error message or anything...it just returns a "1"
(whereas it should return a "0") as far as I can tell. I have read the
PHP...
|
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. When it completes, it can call a success, or a failure
function. The names of these success, or failure functions will differ,
and I'd like to know how I can pass the name of a function to my tool,
and how my tool can call the function, using that...
|
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:
// main.cpp
// This is defined in a C module
extern "C" void fake_qsort(void*, std::size_t, std::size_t,
int (*compare)(const void*, const void*));
|
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 experts.
I would like to produce Javascript classes that can be "subclassed"
with certain behaviors defined at subclass time. There are plenty of
ways to do this through prototyping and other techniques, but these
behaviors need to be static and...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |