473,698 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regarding external function(Ss)

Hi Everyone,

I have seen in some project where functions are declared as extern,
what is the possible reason to do this? To my best understanding, if
some other file wan't to invoke this function, it could very well be
done ny including a header file which specifies the function
prototype...

Dec 17 '06 #1
3 1951
sa*****@yahoo.c o.in wrote:
>
Hi Everyone,

I have seen in some project where functions are declared as extern,
what is the possible reason to do this?
Not knowing that function declarations are extern by default,
might be a reason.

--
pete
Dec 17 '06 #2
sa*****@yahoo.c o.in writes:
I have seen in some project where functions are declared as extern,
what is the possible reason to do this? To my best understanding, if
some other file wan't to invoke this function, it could very well be
done ny including a header file which specifies the function
prototype...
As pete points out, function declarations are extern by default, but
that doesn't really answer the question.

I think you're asking why someone would have a declaration for an
external function (one defined elsewhere) in a source file, rather
than having a "#include" for the header file that declares it.

For example, a program that uses malloc() and free() might contain:

extern void *malloc(size_t) ;
extern void free(void*);

(the "extern" keywords aren't necessary but might be more explicit)
rather than the usual "#include <stdlib.h>".

Both are equivalent as far as the compiler is concerned, assuming the
header contains equivalent declarations. #include'ing a header
effectively copies the contents of that header into your source file.
Later phases of the compiler don't care whether a given function
declaration is from an included header or from the source file itself.

One disadvantage of re-declaring a function in another source file is
that it's too easy to get it wrong. If your declaration doesn't match
the actual declaration of the function, the compiler likely won't be
able to warn you about the error, and any calls will invoke undefined
behavior. You can avoid this by declaring the function in just one
place, in a header file to be #include'd by any source file that needs
it -- including the source file that actually defines the function.
In the case of the standard library functions, and user-defined
libraries as well, this also gives the header the opportunity to play
tricks like defining a macro to be invoked in place of the function.

There's no good reason I can think of to re-declare a function like
this. It's legal, and some programmers will do it that way, but IMHO
it's poor style.

--
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.
Dec 17 '06 #3
pete <pf*****@mindsp ring.comwrites:
sa*****@yahoo.c o.in wrote:
>>
Hi Everyone,

I have seen in some project where functions are declared as extern,
what is the possible reason to do this?

Not knowing that function declarations are extern by default,
might be a reason.
Another might be that the programmer is making it explicit in
conjunction with judicous uses of static functions.
Dec 18 '06 #4

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

Similar topics

3
2291
by: Cristian | last post by:
Hi all, When I download a file with ftp_nb_get, I'd like to show the elapsed time and so I had insert this javascript function in my php page <SCRIPT> function scrivi(num, num2, num3) { document.getElementById("pippo").value=num+":"+num2+"."+num3; } </SCRIPT> that I call when I download the file:
11
1740
by: chetan | last post by:
How to initialise a function pointer for any particular function in C++ ? so that it would clearly specify difference between the functions that are called by different objects of that class ... i.e instead of a.function(); or
4
3628
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is of the type the object is instantiated with. In my test program I have Option<std::string> and Option<long>. Here's the code for OptionBase and Option along with a small helper function. In the code are comments describing my problem, look closely...
12
3088
by: relaxedrob | last post by:
Hi All! I have a page with with the following style information: <link rel="stylesheet" type="text/css" href="/eEmployment/eTech.css" /> <style type="text/css"> DIV.Application { BACKGROUND-IMAGE:url(/someImage.jpg); }
2
2485
by: D. Shane Fowlkes | last post by:
Here's a good one. I've been using an Excel spreadsheet for the past couple of years to calculate a file's Estimated Download Time based off of a solid 50kbs connection (dial up). This is for a downloads page such as: http://www.drpt.virginia.gov/downloads/selectedcat.aspx?ID=12 The formula is basically this: =(((C4*1000*8)/50000)/84600)*1.1 (Estimate is calculated on a modem dial up connection of 50Kbs and transfer
12
2104
by: mohan | last post by:
Hi All, How to implement virtual concept in c. TIA Mohan
27
3119
by: Terry | last post by:
I am getting the following warning for the below function. I understand what it means but how do I handle a null reference? Then how do I pass the resulting value? Regards Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
2
1998
by: Hari2349 | last post by:
Regarding to log4j in java program..Plz help me... -------------------------------------------------------------------------------- Hai, friends i used the log4j.properties file like as below...... log4j.rootLogger=VERBOSE, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppe nder
1
2320
by: subhalalitha | last post by:
There is a requirement in our system. There is one Transaction Monitoring thread which wakes up after every 30 sec and checks for the requests that didnot get responses for "2 min" and sends Timeout Responses to the caller. There is a need to wake up this Thread upon an "event" to send Timeout responses for all the Requests. I tried samples and this combination does not seem to work for me. In short , The thread should wake up...
0
8611
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,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
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...
0
8876
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 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...
0
7741
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, 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...
1
6531
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 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...
0
5867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
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...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.