C - Mismatched function prototype and definition for "static" function

Cloud

I am trying to find some official confirmation on a theory with respect to C functions. In a simple project of mine, I have a function which I only want to be visible within the .c file in which it is defined. The function prototype is:

static int sum(int a, int b);

The function definition is:

int sum(int a, int b) {
   return (a+b);
}

Upon analysis of the build output, link maps, etc, it seems that the function is indeed static. I'm surprised that I don't get any build warnings or errors either. However, is there anything in terms of documentation (ie: specific line in the GCC manual) that can confirm this behavior, or what is expected?

I have found the equivalent of this question for C++ (Static keyword in function declaration can be missing in function definition?), but I am looking for the answer with respect to pure C.

Thank you.

user3386109

You can download the full specification from http://www.iso.org/iso/home/store/catalogue_ics/catalogue_detail_ics.htm?csnumber=57853

for 238 Swiss Francs, and I'm sure that will have the answer. Otherwise, the best source I have is from "The C Programming Language" 2nd edition by K&R, section 4.6 on page 83 (emphasis added)

"The external static declaration is most often used for variables, but it can be applied to functions as well. Normally, function names are global, visible to any part of the entire program. If a function is declared static, however, its name is invisible outside of the file in which it is declared."

Note that the quote only refers to the declaration of the function, not its definition, although it's common practice for static functions, that the definition serves as the declaration as well.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C function definition/prototype

From Dev

Prototype vs function definition

From Dev

Prototype vs function definition

From Dev

static function definition in header

From Dev

static function definition in header

From Dev

Uncaught Error: Mismatched anonymous define() module: function definition(name, global)

From Dev

Uncaught Error: Mismatched anonymous define() module: function definition(name, global)

From Dev

Definition prototype for a function accepting an empty Lambda Expression

From Dev

Static function definition that resembles a pointer to member function

From Dev

Static function definition that resembles a pointer to member function

From Dev

Definition of a function in a C program

From Dev

Function definition in C struct?

From Dev

C function definition and declaration

From Dev

Can an __attribute__ specifier be used with both the function prototype and the function definition?

From Dev

C program issues with function prototype

From Dev

C typedef for function prototype dlsym

From Java

What is a "static" function in C?

From Dev

Violating static function in C

From Dev

Purpose of static function in C

From Dev

function definition in BNF C grammar

From Dev

c, function definition following struct

From Dev

Find function definition in C++

From Dev

Weird declaration and definition of a function in C

From Dev

Elegant function definition in C++

From Dev

Find function definition in C++

From Dev

function definition in BNF C grammar

From Dev

Elegant function definition in C++

From Dev

Is the 'main' function classified as a function definition in C?

From Dev

Function prototype or not?

Related Related

HotTag

Archive