r/C_Programming • u/Just_Government3790 • Sep 12 '26
Question What C function would you delete and rewrite first, and why?
For me it's fnmatch - mostly because it's 40 year's old and smell's funny.
95
Upvotes
View all comments
Show parent comment
2
u/flatfinger Sep 14 '26
Worse, the Committee seems to have been and continue to be oblivious to the fact that much of C's usefulness revolved around corner cases where whose behavior would be impossible to predict without information the language had no way of conveying, but which the execution environment might convey to the programmer via means outside the language. When the Standard noted that implementations may process cases where it waives jurisdiction "in a documented manner characteristic of the environment", it failed to recognize a useful class of implementations that will process those corner cases "in a manner characteristic of the environment, which will be documented to the extent that the environment happens to document it."
Worse, the way the Standard accommodates optimizing transforms that would be useful for some kinds of program but inappropriate for others is to characterize as "undefined behavior" any corner case whose behavior might be affected thereby, rather than recognizing a category of implementations that perform such transforms, and allowing them to affect program behavior in certain ways. For example, it may be useful to specify that if a piece of code with a single statically reachable exit could not have any side effect other than preventing the execution of code following the exit, a compiler may cleanly omit the code entirely, but behavior would need to be consistent with either executing the code as written, or cleanly omitting it, but would be considered "defined" in either case.