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

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

Besides what Olin already said, I guess too many people were taught C using K&R book, which was great at the time, but it completely neglects modern SW engineering best practices (encapsulation...

posted 1y ago by Lorenzo Donati‭

Answer
#1: Initial revision by user avatar Lorenzo Donati‭ · 2023-07-09T13:52:56Z (over 1 year ago)
Besides what Olin already said, I guess too many people were taught C using K&R book, which was great at the time, but it completely neglects modern SW engineering best practices (encapsulation, data hiding, modularization, etc.), many of which were popularized to the wider programmer audience by C++ and later by Java, since these languages support OOP and in this paradigm modularization (which `static` in C is for) is essentially a must (in C++ you have namespaces, classes and all sort of mechanism to do so).

In particular, separation of the interface of a module from the implementation is essentially made using `static` vs `extern` functions: write the interface in a header file where you *declare* all the public functions the module must export, then include the header in the corresponding source file (`.c` file) where you implement the public functions using all the private (`static`) helper functions you need.

One of the staple of good SW design is to avoid *fat interfaces*, i.e. interfaces with a lot of functions that don't need to be public, but are there "just in case". C programmers that cram their headers with all the functions in their modules probably haven't been exposed to OOP languages or are too inexpert in modern C programming practices (you can do OOP even in C, but it requires quite a lot of discipline since the language won't help you there)

Another alternative is that they are "old timers" that grew up with assembly and C at low level, where legacy code written for "bare metal" systems didn't need too much SW engineering best practices to work well. After all, if all you have is an MCU with 16k or so of Flash and some kiBs of RAM (and you are a good programmer) you can write pretty good software even using C as an higher level assembly. 

The problem is that this doesn't scale well for bigger systems. Once your project code base size hits the thousands of source code lines of C you are in for very nasty surprises if you don't employ higher level techniques, and one of the most basic techniques is using `static` to compartmentalize functions in the module they belong to.