Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

83%
+8 −0
Q&A What are disadvantages of static functions (ie functions with internal linkage) in C?

Functions in C have external linkage by default. In other words, the storage class specifier extern is applied to functions by default, with the effect that they are visible to all translation unit...

3 answers  ·  posted 1y ago by Lover of Structure‭  ·  last activity 1y ago by Dirk Herrmann‭

Question c linkage
#7: Nominated for promotion by user avatar Alexei‭ · 2023-07-13T08:26:29Z (over 1 year ago)
#6: Post edited by user avatar Lover of Structure‭ · 2023-07-09T13:54:45Z (over 1 year ago)
disambiguation (minor) of wording
  • Functions in C have external linkage by default. In other words, the storage class specifier `extern` is applied to functions by default, with the effect that they are visible to all translation units.
  • The storage class specifier `static` gives functions internal linkage and restricts visibility to the given translation unit.
  • Some comparison to other programming languages is instructive:
  • - In Java, one is taught from early on to give thought to the right choice of *access modifier*, which in most cases means choosing between `public` and `private`.
  • - In Pascal, one can define functions (and procedures, ie functions without a return type) within other functions (or procedures). However in C, functions can only be defined at file scope, giving them global visibility by default (and thereby making us have to worry about internal vs external linkage).
  • Restricting visibility is a good thing. But I have encountered relatively few functions marked `static` in production code that could have been given internal linkage. We can therefore ask: **What are disadvantages of `static` functions (ie functions with internal linkage) in C?**
  • An admittedly opinion-based way of asking would be: **Why aren't `static` functions used much more widely in C?** (The answer might simply be "traditionally people don't bother to change the default linkage for functions from external to internal".)
  • Functions in C have external linkage by default. In other words, the storage class specifier `extern` is applied to functions by default, with the effect that they are visible to all translation units.
  • The storage class specifier `static` gives functions internal linkage and restricts visibility to the given translation unit.
  • Some comparison to other programming languages is instructive:
  • - In Java, one is taught from early on to give thought to the right choice of *access modifier*, which in most cases means choosing between `public` and `private`.
  • - In Pascal, one can define functions (and procedures, ie functions without a return type) within other functions (or procedures). However in C, functions can only be defined at file scope, giving them global visibility by default (and thereby making us have to worry about internal vs external linkage).
  • Restricting visibility is a good thing. But I have encountered relatively few functions marked `static` in production code, even though they []()could have been given internal linkage. We can therefore ask: **What are disadvantages of `static` functions (ie functions with internal linkage) in C?**
  • An admittedly opinion-based way of asking would be: **Why aren't `static` functions used much more widely in C?** (The answer might simply be "traditionally people don't bother to change the default linkage for functions from external to internal".)
#5: Post edited by user avatar Lover of Structure‭ · 2023-07-08T21:29:20Z (over 1 year ago)
  • Functions in C have external linkage by default. In other words, the storage class specifier `extern` is applied to functions by default, with the effect that they are visible to all translation units.
  • The storage class specifier `static` gives functions internal linkage and restricts visibility to the given translation unit.
  • Some comparison to other programming languages is instructive:
  • - In Java, one is taught from early on to give thought to the right choice of *access modifier*, which in most cases means choosing between `public` and `private`.
  • - In Pascal, one can define functions (and procedures, ie functions without a return type) within other functions (or procedures). However in C, functions can only be defined at file scope, giving them global visibility by default.
  • Restricting visibility is a good thing. But I have encountered relatively few functions marked `static` in production code that could have been given internal linkage. We can therefore ask: **What are disadvantages of `static` functions (ie functions with internal linkage) in C?**
  • An admittedly opinion-based way of asking would be: **Why aren't `static` functions used much more widely in C?** (The answer might simply be "traditionally people don't bother to change the default linkage for functions from external to internal".)
  • Functions in C have external linkage by default. In other words, the storage class specifier `extern` is applied to functions by default, with the effect that they are visible to all translation units.
  • The storage class specifier `static` gives functions internal linkage and restricts visibility to the given translation unit.
  • Some comparison to other programming languages is instructive:
  • - In Java, one is taught from early on to give thought to the right choice of *access modifier*, which in most cases means choosing between `public` and `private`.
  • - In Pascal, one can define functions (and procedures, ie functions without a return type) within other functions (or procedures). However in C, functions can only be defined at file scope, giving them global visibility by default (and thereby making us have to worry about internal vs external linkage).
  • Restricting visibility is a good thing. But I have encountered relatively few functions marked `static` in production code that could have been given internal linkage. We can therefore ask: **What are disadvantages of `static` functions (ie functions with internal linkage) in C?**
  • An admittedly opinion-based way of asking would be: **Why aren't `static` functions used much more widely in C?** (The answer might simply be "traditionally people don't bother to change the default linkage for functions from external to internal".)
#4: Post edited by user avatar Lover of Structure‭ · 2023-07-08T20:04:18Z (over 1 year ago)
  • Functions in C have external linkage by default. In other words, the storage class specifier `extern` is applied to functions by default, with the effect that they are visible to all translation units.
  • The storage class specifier `static` gives functions internal linkage and restricts visibility to the given translation unit.
  • Some comparison to other programming languages is instructive:
  • - In Java, one is taught from early on to give thought to the right choice of *access modifier*, which in most cases means choosing between `public` and `private`.
  • - In Pascal, one can define functions (and procedures, ie functions without a return type) within other functions (or procedures). However in C, functions can only be defined at file scope, giving them global visibility by default.
  • Restricting visibility is a good thing. We can therefore ask: **What are disadvantages of `static` functions (ie functions with internal linkage) in C?**
  • An admittedly opinion-based way of asking would be: **Why aren't `static` functions used much more widely in C?** (The answer might simply be "traditionally people don't bother to change the default linkage for functions from external to internal".)
  • Functions in C have external linkage by default. In other words, the storage class specifier `extern` is applied to functions by default, with the effect that they are visible to all translation units.
  • The storage class specifier `static` gives functions internal linkage and restricts visibility to the given translation unit.
  • Some comparison to other programming languages is instructive:
  • - In Java, one is taught from early on to give thought to the right choice of *access modifier*, which in most cases means choosing between `public` and `private`.
  • - In Pascal, one can define functions (and procedures, ie functions without a return type) within other functions (or procedures). However in C, functions can only be defined at file scope, giving them global visibility by default.
  • Restricting visibility is a good thing. But I have encountered relatively few functions marked `static` in production code that could have been given internal linkage. We can therefore ask: **What are disadvantages of `static` functions (ie functions with internal linkage) in C?**
  • An admittedly opinion-based way of asking would be: **Why aren't `static` functions used much more widely in C?** (The answer might simply be "traditionally people don't bother to change the default linkage for functions from external to internal".)
#3: Post edited by user avatar Lover of Structure‭ · 2023-07-08T16:28:12Z (over 1 year ago)
speculative answer added
  • Functions in C have external linkage by default. In other words, the storage class specifier `extern` is applied to functions by default, with the effect that they are visible to all translation units.
  • The storage class specifier `static` gives functions internal linkage and restricts visibility to the given translation unit.
  • Some comparison to other programming languages is instructive:
  • - In Java, one is taught from early on to give thought to the right choice of *access modifier*, which in most cases means choosing between `public` and `private`.
  • - In Pascal, one can define functions (and procedures, ie functions without a return type) within other functions (or procedures). However in C, functions can only be defined at file scope, giving them global visibility by default.
  • Restricting visibility is a good thing. We can therefore ask: **What are disadvantages of `static` functions (ie functions with internal linkage) in C?** A more opinion-based way of asking would be: **Why aren't `static` functions used much more widely in C?**
  • Functions in C have external linkage by default. In other words, the storage class specifier `extern` is applied to functions by default, with the effect that they are visible to all translation units.
  • The storage class specifier `static` gives functions internal linkage and restricts visibility to the given translation unit.
  • Some comparison to other programming languages is instructive:
  • - In Java, one is taught from early on to give thought to the right choice of *access modifier*, which in most cases means choosing between `public` and `private`.
  • - In Pascal, one can define functions (and procedures, ie functions without a return type) within other functions (or procedures). However in C, functions can only be defined at file scope, giving them global visibility by default.
  • Restricting visibility is a good thing. We can therefore ask: **What are disadvantages of `static` functions (ie functions with internal linkage) in C?**
  • An admittedly opinion-based way of asking would be: **Why aren't `static` functions used much more widely in C?** (The answer might simply be "traditionally people don't bother to change the default linkage for functions from external to internal".)
#2: Post edited by user avatar Lover of Structure‭ · 2023-07-08T15:53:28Z (over 1 year ago)
  • What are disadvantages of `static` functions (ie functions with internal linkage) in C?
  • What are disadvantages of static functions (ie functions with internal linkage) in C?
#1: Initial revision by user avatar Lover of Structure‭ · 2023-07-08T13:03:51Z (over 1 year ago)
What are disadvantages of `static` functions (ie functions with internal linkage) in C?
Functions in C have external linkage by default. In other words, the storage class specifier `extern` is applied to functions by default, with the effect that they are visible to all translation units.

The storage class specifier `static` gives functions internal linkage and restricts visibility to the given translation unit.

Some comparison to other programming languages is instructive:
 - In Java, one is taught from early on to give thought to the right choice of *access modifier*, which in most cases means choosing between `public` and `private`.
 - In Pascal, one can define functions (and procedures, ie functions without a return type) within other functions (or procedures). However in C, functions can only be defined at file scope, giving them global visibility by default.

Restricting visibility is a good thing. We can therefore ask: **What are disadvantages of `static` functions (ie functions with internal linkage) in C?** A more opinion-based way of asking would be: **Why aren't `static` functions used much more widely in C?**