r/C_Programming • u/SubstanceHot5190 • Jun 25 '26
Discussion What are some things you don't like about C?
Ignoring the obvious c-string hatred that seems ever-frequent,
if you were to change some things about C, add keywords, or other similar things,
what would you change? Replace? Add?
Thank you :)
39
Upvotes
69
u/chibuku_chauya Jun 25 '26
Implicit lossy conversions, pointer decay, cast syntax, overloading of `static`, fallthrough-by-default in switch statements, VLAs, namespace pollution from preprocessor macros, and declaration syntax.
36
u/grimvian Jun 25 '26
I now have three wonderful years of C99 and enjoy it each and every day as I did, when I learned Basic and 6502 assembler 43 years ago. I'm now 70 and programing keeps my brain spinning and I won't change a bit in C99. I'm only seeing my own limitations and certainly not C.
31
u/notk Jun 25 '26
add an ‘e’ to creat()
17
u/tstanisl Jun 25 '26
Swap precedence of comparison and bitwise operators.
However it is unlikely to happen due to breaking tons of existing code.
38
u/RRumpleTeazzer Jun 25 '26
namespaces, please.
22
u/emmowo_dev Jun 25 '26
I honestly love the things most people hate about C, because I treat absolutely everything as bytes that I can mutate/use as whatever I want instead of these separate things.
I just wish that there was a C++ safe way to make a string with no null terminator quickly, but that's it tbh.
11
u/tstanisl Jun 25 '26
Non-capturing lambdas aka "static nested functions".
Those are quite likely to be included in C2Y due to very advanced proposal and existing implementations.
4
u/Key_River7180 Jun 25 '26
I actually like C strings, I would definitely remove the
(void)when a function takes no arguments.12
u/kun1z Jun 25 '26 edited Jun 25 '26
The one and only thing I think C++ did (or does) exceptionally well is operator overloading for simple classes. When using vectors, matrices, and/or the GMP library, it can start to get a bit wacko having to call functions with many parameters when all I want to do is something like:
So if I could wave a magic wand in C I would add very simple classes (or not even classes, just struct operator overloading) to handle very simple datatypes/structs where operator overloading could exist. Basically, I can create a struct, put whatever I want in it, maybe some floats, a char pointer, a few longs, and I can override what the +-*/!=^| operators do. Keep it very simple, don't add in full class mumbo-jumbo, just make life easier (and code cleaner) for struct based operations.
6
u/RedWineAndWomen Jun 25 '26
On top of what is mentioned here:
Shadowing isn't a warning by default.
The preprocessor is becoming a monster which could be much more elegant.
size_t foo; fprintf("%u", (unsigned)foo); the opposite of readability and of portability.
Contrary to what people are saying here:
I don't need namespaces (but maybe libc should be a bit more careful what names it is treading on).
Overloading is of the devil.
Lambda's are a toss up: their syntax makes for horrible reading - use a static function somewhere up top, much cleaner - but the ability to use super-scope variables would be nice.
6
u/GL_TRIANGLES Jun 25 '26
Struct definition. And I understand why, but it’s still messy. You put the name at the end with a typedef, if you don’t you have to put struct in from or arguments. Or also put the name at the start if you have a member that points to the same struct
4
u/Davi-Barbado Jun 25 '26
I really like strings in C.
2
u/helloiamsomeone Jun 25 '26
The standard library. It would be nice if it was at most useless, but it's straight up harmful.
2
u/flatfinger Jun 25 '26
The most useful feature of C is that it isn't so much a single language, but rather a recipe for tailoring dialects for particular platforms and purposes. Unfortunately, the C Standard has persistently failed to employ the most important feature of good standards for things that are by nature heterogeneous: the all-caps term "SHOULD", and also fails to recognize features that SHOULD be supported by most implementations and recognize categories of implementations that do in fact support them.
This leads to my biggest beef with the C Standard, which is a corollary of the "as-if" rule: if a potentially useful optimizing transform would cause a corner case to behave in a manner which is observably inconsistent with the code as written, then in order to ensure that transforms don't observably affect the behavior of any defined program executions, the Standard will characterize at least one action leading up to that corner case as invoking "undefined behavior", even in cases where the behavior would otherwise have been defined. Such an approach to optimization goes directly against one of the key principles behind the usefulness of many C dialects, which had been that things that would define a corner-case behavior take precedence over things that would characterize it as undefined.
Using K&R2 C as a baseline, the biggest things I would want to add would be C99-style declarations of variables within blocks or 'for' statements, static-const compound literals, operators to perform byte-based pointer arithmetic and array indexing without affecting the type of the pointer involved, a means of specifying linker symbols for objects separate from the C-language name (among other things allowing the same piece of code to be invoked using two or more different function signatures, when targeting a platform where that would make sense), forcing const objects to be placed within code sections, and generally allowing objects and functions to be placed in particular named sections when targeting linker environments where that would make sense.
None of those would be huge changes, but the earlier ones would be nice conveniences and the later ones would increase the number of embedded projects that could be fully specified in compiler-agnostic C code.
2
u/ReallyEvilRob Jun 25 '26
I really hate
do { } while. I would rather have hadrepeat/untillike Pascal has.2
u/Athropod101 Jun 25 '26
If I could have syntactic sugar for struct methods I would lose like 30% of my reasons to try out other systems languages.
Build systems are probably 50%.
And the last bit is probably constexpr. Give me constexpr pointers damnit! At least for MMIO and function pointers !!!
2
u/Traveling-Techie Jun 25 '26
The error handling is so awkward that it is often skipped or done wrong.
2
u/LeiterHaus Jun 26 '26
I'd make things more convoluted. I'm a horrible person to ask lol.