Extern keyward on function in C


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Programming Extern keyward on function in C
# 1  
Extern keyward on function in C

I saw a header (.h) file with mixture of "regular" function declarations and other extern function declarations. As I was told all function declarations are implicitly external and the extern on functions declarations is superfluous. Here my focus is on function declaration, not variable yet.
Code:
int fq_read_length (char *data);
char *fa_count (char *start, int length);
extern int get_parainfo (char *full, Queue *head, char type);
extern char *fastq_relocate (char *data, int offset, int length);
extern char *jump (char *target, char type, float sampling_rate);
extern char *get_right_sp (char *start_point ,char type);
extern char *check_fmt (Queue *info, Queue *tail, char *start_point, char type);
int total_full_check (bloom * bl, char *p, int length, float tole_rate, F_set *File_head);
extern int fastq_read_check (char *begin, int length, char mode, bloom * bl, float tole_rate, F_set *File_head);
extern int fasta_read_check (char *begin, int length, char mode, bloom * bl, float tole_rate, F_set *File_head);
void isodate(char* buf);
int total_subscan (bloom *bl, F_set *File_head, char *begin, char *start_point, int read_length, int true_length, float tole_rate, char mode, char type);

Then why is extern on function declaration still used, and what is the benefit? Thanks!

Last edited by yifangt; 04-13-2016 at 05:54 PM..
# 2  
You can define a function to be static which makes it available only to functions calling that function from the same file in which that static function is defined.

If a function is declared to be external in a header that is included in a file that defines one or more of those functions as static, I think the results are undefined, but I'd have to do some digging through the C Standard to be sure that a diagnostic wouldn't be required in this case.
# 3  
All functions are implicitly extern, yes, but there's sometimes more to be said.

Code:
// To use a C function from C++ you must warn the linker to expect 
// the symbol _functionname, not a C++ hashed overload like @kldsgjlakgjadls
extern "C" int functionname(int);

Also different linking specifications for different kinds of libraries, i.e. so's and dll's vs statically linked things. Sometimes the linker can handle that for you, but it's often more efficient, at least, to warn it in advance that it will be calling external library code.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #984
Difficulty: Medium
FreeBSD was the most popular open-source BSD operating system, accounting for more than three-quarters of all installed BSD systems.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies

2. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

3. Programming

C header file and extern

In the header file data.h i got: const char ack_msg = "ack: received your msg\n"; In the code file server.c i got: extern const char ack_msg; And else it is only used in a function call: user$ grep ack_msg *c *h server.c:extern const char ack_msg; server.c: n = write(clientsfd,... (5 Replies)
Discussion started by: tornow
5 Replies

4. Programming

segmentation fault for extern

Why this is happening when both of them compiled together and run? I am getting segmentation fault SIGSEGV. File1.c: int arr; File2.c: extern int *arr; int main() { arr = 100; } (3 Replies)
Discussion started by: royalibrahim
3 Replies

5. Shell Programming and Scripting

Return a value from called function to the calling function

I have two scripts. script1.sh looks -------------------------------- #!/bin/bash display() { echo "Welcome to Unix" } display ----------------------------- Script2.sh #!/bin/bash sh script1.sh //simply calling script1.sh ------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies

6. UNIX for Dummies Questions & Answers

fetchmail and forward to an extern address

Hi, I'm searching for an solution for the following problem. I want fetch some mails via pop3 from a@a.com with fetchmail. That works perfectly. Now any incoming mail should forwarded to b@b.com via smtp obv. But I don't know how to configure that. All online tutorials describe forwarding to... (0 Replies)
Discussion started by: mcW
0 Replies

7. Linux

Problem mounting extern hd (fedora 9)

Hi there, I'm having a bit of a strange problem which I would appreciate some help with. The Problem: I have two external hard drives, but I'm borrowing one off my parents to copy data too (one of mine, which is identical to theirs - WD MyBook 300g - is on its way out). Fedora 9 recognizes... (3 Replies)
Discussion started by: lasthidingplace
3 Replies

8. Programming

Extern variable.

file1.c int a1; int main() { a1 = 2; printf("\na1 = %d\n", a1); next(); printf("\na1 = %d\n", a1); next1(); printf("\na1 = %d\n", a1); } file2.c #include <stdio.h> int b1 = 0; void next(void) (1 Reply)
Discussion started by: Tanvirk
1 Replies

9. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

10. Programming

extern for functions

Hi, Please let me know if the extern keyword is necessary for using functions which is defined and declared in another file and and used in a different file where both these files are linked together. thanks (8 Replies)
Discussion started by: naan
8 Replies

Featured Tech Videos