473,372 Members | 859 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,372 software developers and data experts.

[Q]extern in front of function definition?

Hi,

BSD code has following hcreate function definition in hsearch.c
under lib/libc/db/hash/hsearch.c.
Here, why is 'extern' used ? What's the purpose of it? How come
in infront of functions definition ? ( Usually 'extern' is placed in
front of function declaration....)

extern int
hcreate(nel)
size_t nel;
{
HASHINFO info;

info.nelem = nel;
info.bsize = 256;
info.ffactor = 8;
info.cachesize = 0;
info.hash = NULL;
info.lorder = 0;
dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR, 0600, &info, 0);
return (dbp != NULL);
}
....

Mar 26 '07 #1
11 3329
dj****@gmail.com said:
Hi,

BSD code has following hcreate function definition in hsearch.c
under lib/libc/db/hash/hsearch.c.
Here, why is 'extern' used ?
No real reason.
What's the purpose of it?
Someone liked typing, I guess.
How come
in infront of functions definition ?
It means that the function has external linkage (which it has anyway by
default).
( Usually 'extern' is placed in
front of function declaration....)
Definitions are also declarations.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 26 '07 #2
Richard Heathfield <r...@see.sig.invalidwrote:
djh...@gmail.com said:
BSD code has following hcreate function definition in hsearch.c
under lib/libc/db/hash/hsearch.c.
Here, why is 'extern' used ?

No real reason.
What's the purpose of it?

Someone liked typing, I guess.
I recall one chap on clc insists on redundantly initialising
_all_ automatic variables. Some people have strange notions of
what's real... ;-)

--
Peter

Mar 27 '07 #3
Peter Nilsson said:
Richard Heathfield <r...@see.sig.invalidwrote:
>djh...@gmail.com said:
BSD code has following hcreate function definition in hsearch.c
under lib/libc/db/hash/hsearch.c.
Here, why is 'extern' used ?

No real reason.
What's the purpose of it?

Someone liked typing, I guess.

I recall one chap on clc insists on redundantly initialising
_all_ automatic variables. Some people have strange notions of
what's real... ;-)
<grinWell, I have my reasons, and they are well known here. Can you
come up with a plausible reason for extern-qualifying functions?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 27 '07 #4
Richard Heathfield <rj*@see.sig.invalidwrites:
Peter Nilsson said:
>Richard Heathfield <r...@see.sig.invalidwrote:
>>djh...@gmail.com said:
BSD code has following hcreate function definition in hsearch.c
under lib/libc/db/hash/hsearch.c.
Here, why is 'extern' used ?

No real reason.

What's the purpose of it?

Someone liked typing, I guess.

I recall one chap on clc insists on redundantly initialising
_all_ automatic variables. Some people have strange notions of
what's real... ;-)

<grinWell, I have my reasons, and they are well known here. Can you
come up with a plausible reason for extern-qualifying functions?
As a matter of fact, I can.

In general, functions should be declared as static unless there's a
specific requirement for them to be visible outside the current
translation unit. Explicitly declaring externally visible functions
as "extern", though it doesn't do anything for the compiler, acts as
an explicit reminder to the reader that the function really is
intended to be externally visible, rather than just being accidentally
visible because that's the default.

(I'm not sure I believe that, but I do think its plausible.)

--
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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 27 '07 #5
Keith Thompson said:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Can you
come up with a plausible reason for extern-qualifying functions?

As a matter of fact, I can.

In general, functions should be declared as static unless there's a
specific requirement for them to be visible outside the current
translation unit. Explicitly declaring externally visible functions
as "extern", though it doesn't do anything for the compiler, acts as
an explicit reminder to the reader that the function really is
intended to be externally visible, rather than just being accidentally
visible because that's the default.

(I'm not sure I believe that, but I do think its plausible.)
I'm impressed. It is indeed a plausible reason.

<SFX: removes hat>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 27 '07 #6
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>In general, functions should be declared as static unless there's a
specific requirement for them to be visible outside the current
translation unit. Explicitly declaring externally visible functions
as "extern", though it doesn't do anything for the compiler, acts as
an explicit reminder to the reader that the function really is
intended to be externally visible, rather than just being accidentally
visible because that's the default.
It also saves you from having to add the "extern" when you copy it
to the .h file.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 27 '07 #7
Richard Heathfield wrote On 03/27/07 03:10,:
Peter Nilsson said:

>>Richard Heathfield <r...@see.sig.invalidwrote:
>>>djh...@gmail.com said:

BSD code has following hcreate function definition in hsearch.c
under lib/libc/db/hash/hsearch.c.
Here, why is 'extern' used ?

No real reason.
What's the purpose of it?

Someone liked typing, I guess.

I recall one chap on clc insists on redundantly initialising
_all_ automatic variables. Some people have strange notions of
what's real... ;-)


<grinWell, I have my reasons, and they are well known here. Can you
come up with a plausible reason for extern-qualifying functions?
"Functions" in general, no. But "this function," yes!

Observation #1: The function is defined without a prototype,
using a K&R-style argument list.

Observation #2: The function is described as being part of
the BSD source.

Recollection: BSD's origins antedate the first C Standard.

Plausible supposition: This function was written to be
compiled by pre-Standard compilers, in the wild and wooly days
when every compiler was its own language definition. Some of
those compilers may have done Something Good (or avoided doing
Something Bad) with the now-useless extern.

Counter-indications: The use of size_t suggests more recent
provenance, as do the "untagged" names of the struct elements.

Cavalier dismissal of counter-indications: One or more
programmers have visited the source since its original writing,
and have brought it incompletely up-to-date.

--
Er*********@sun.com
Mar 27 '07 #8
Eric Sosman said:
Some of
those compilers may have done Something Good (or avoided doing
Something Bad) with the now-useless extern.
Eric - My solicitor will be in touch with you about these trademark
violations. You might want to get your chequebook ready.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 27 '07 #9
Richard Tobin wrote, On 27/03/07 11:12:
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>In general, functions should be declared as static unless there's a
specific requirement for them to be visible outside the current
translation unit. Explicitly declaring externally visible functions
as "extern", though it doesn't do anything for the compiler, acts as
an explicit reminder to the reader that the function really is
intended to be externally visible, rather than just being accidentally
visible because that's the default.

It also saves you from having to add the "extern" when you copy it
to the .h file.
It does not save me having to do that since C does not require it. Of
course, if your coding standard does...
--
Flash Gordon
Mar 27 '07 #10
In article <pl************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:
>>In general, functions should be declared as static unless there's a
specific requirement for them to be visible outside the current
translation unit. Explicitly declaring externally visible functions
as "extern", though it doesn't do anything for the compiler, acts as
an explicit reminder to the reader that the function really is
intended to be externally visible, rather than just being accidentally
visible because that's the default.
>It also saves you from having to add the "extern" when you copy it
to the .h file.
>It does not save me having to do that since C does not require it. Of
course, if your coding standard does...
Hmm, that's true. I think I just do it out of some habit acquired in
the mists of time.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 27 '07 #11
On 27 Mar 2007 23:49:03 GMT, ri*****@cogsci.ed.ac.uk (Richard Tobin)
wrote:
>In article <pl************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:
>>>In general, functions should be declared as static unless there's a
specific requirement for them to be visible outside the current
translation unit. Explicitly declaring externally visible functions
as "extern", though it doesn't do anything for the compiler, acts as
an explicit reminder to the reader that the function really is
intended to be externally visible, rather than just being accidentally
visible because that's the default.
>>It also saves you from having to add the "extern" when you copy it
to the .h file.
>>It does not save me having to do that since C does not require it. Of
course, if your coding standard does...

Hmm, that's true. I think I just do it out of some habit acquired in
the mists of time.
Hmm here, too. I don't use extern in headers, but I use it when I add
a single prototype for an external function. Same reason as you, I
guess.

--
Al Balmer
Sun City, AZ
Mar 28 '07 #12

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

Similar topics

18
by: tweak | last post by:
What's the best way to use extern when using multiplefiles that is easiest to maintain? Is it best to declare: extern int a; in a header file and include the header file in all files except...
19
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default...
29
by: DevarajA | last post by:
Can anyone explain me what extern is used for? I thought it was used to declare variables definited in other files, but i can do that also without extern. /*file a.c*/ int a=5; int main() {...
5
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining...
17
by: Tapeesh | last post by:
I would like to know what is the expected behaviour of C compilers when an extern decleration is intialized. When the following code is compiled using gcc //File extern.c int arr ; int a ;
5
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
16
by: Martin Jørgensen | last post by:
Hi, Problem: ======== Some of my output functions are beginning to take pretty many arguments... I mean.... We're talking about 10-15 arguments :-) So I thought to myself, perhaps this is...
7
by: Travis | last post by:
I'm relatively new to externs and function pointers but have inherited the task of modifying some existing code. I have something like this. extern void myExternFunc (MenuItem *item, void *...
3
by: polas | last post by:
I have a quick question - I have used extern quite a bit in relation to variables, however was wondering if its applicable to function prototypes too? For instance, I have a file called a.c - a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.