MOHAMED
MOHAMED

Reputation: 43518

Difference between static function and non static function in C

I'm developing an embedded application on VxWorks.

I know that the static function is called only in the file where defined and the non static function is called in any file in the source project.

I'm wondering if there is a difference between static and non static function concening execution time and concerning memory

Upvotes: 10

Views: 9960

Answers (3)

David Grayson
David Grayson

Reputation: 87396

It depends on your compiler. Static functions can theoretically be optimized better because the compiler will know all the places where they are being called. You should be able to get an assembly listing from your compiler and find out for yourself if they are more efficient.

Upvotes: 4

simonc
simonc

Reputation: 42175

There is no difference in execution times or runtime memory requirements.

Some (many?) linkers will find it easier to spot unused static functions and drop them so they might encourage smaller code size.

Upvotes: 3

Jon
Jon

Reputation: 437376

There is absolutely no performance difference. The the only thing the static keyword does on functions is given them internal linkage, which means they are only accessible in the file they are defined in.

Upvotes: 18

Related Questions