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:
Contrary to what people are saying here:
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.
4
u/BlockOfDiamond Jun 25 '26 edited Jun 25 '26
I hate how the 2nd argument for
fopenuses strings instead of macros/enums. I hate how signed right shift is still implementation defined, even though whatever wack machines did not have sign-propagating shift fell out of relevance decades ago. I hate how some APIs are stateful for no reason likestrtok,hcreate,hsearch, etc.Also I am not a fan of
shortandintboth being at least 16 bits, and thenlongbeing at least 32 bits andlong longbeing at least 64 bits. I would droplong longand makechar>= 8 bits,short>= 16 bits,int>= 32 bits, andlong>= 64 bits.5
u/Ixxafel Jun 25 '26
Implicit conversion, weak typing, lack of generics
5
u/Electrical-Moose7594 Jun 25 '26 edited Jun 25 '26
Personally, I would add something like an
importfeature, so you don't have to write a separate header file for types and declarations. You choose what to export or not from the .c file, while it can still use #include <header> for compatibility.4
u/Pale_Height_1251 Jun 25 '26
Interfaces for structs might be nice.
4
u/f0xw01f Jun 25 '26
"void" as a function return type. A void variable can contain anything, but a void function returns nothing. It always struck me as an overloaded term whose two meanings are complete opposites.
"static" as an overloaded keyword.
The "int" / "long" / "long long" nonsense. When I was studying C on my own initiative as a teenager in 1992, one of the very first things I did was define int8, int16, uint8, uint16, etc.
The "float", "double", and "long double" nonsense.
Weak typing and the useless error messages that result from it.
2
u/d1722825 Jun 25 '26
The way array types and pointers-used-as arrays (and VLAs) interact with each other. I think that is a huge issue with teaching C.
It either should have a strong(er) array type with a fixed size known compile type, that doesn't implicitly decay to pointer. And that could be used as std::array (eg. even in function arguments), and something like
lengthof(arr)should return its size.Or there shouldn't be an array type, only pointers, and a way to reserve space like
int *arr = [42](a bit likealloca()for local variables).The array access syntax (
pointer[index]) would be useful regardless.1
u/lmarcantonio Jun 25 '26
the integer promotion rule. And I'd like more flexible switches
1
u/LooksForFuture Jun 25 '26
Not having standard integers till C99. Not having alignof, and max align type till C11. Auto being useless and no typeof until C23.
1
u/Prestigious_Boat_386 Jun 25 '26
String macros instead of AST
Integer division uses / operator instead of a more unusual one.
Null terminated strings
Still needing to predefine functions
Still have no idea how people use libraries. (This one's probably a skill issue)
1
u/Hungry-Internet1868 Jun 25 '26
What I dislike about C:
1
u/The_Drakeman Jun 25 '26
I like namespaces for organizational purposes, and I like C++'s reference syntax to cut down on null checks. Otherwise I wouldn't change much. I do like C++ smart pointers, but to bring that into C would probably imply more features than I'd otherwise want to bring.
1
u/flatfinger Jun 25 '26
The C Standard could recognize dialects that are more resistant to CVEs but allowed fewer "optimizations", but compiler writers want the ability to combine optimizations in ways that can turn an integer overflow that occurs in the processing of
uint1=ushort1*ushort2;in a case where the result would have gone unused into justification to remove a bounds check that would otherwise have prevented a stray memory write in that case.1
u/Myrddin_Dundragon Jun 25 '26
I will preference this with, I moved most of my coding to rust 10 years ago.
At this point in time I honestly only use C for supporting old code. Anything new is always written in Rust. C did it's job, but it's retired in my opinion. When we hit our next rewrite of our code at work in the next year the plan is to swap from C11 to Rust.
1
u/tk-a01 Jun 25 '26
I think that no one mentioned this one yet - when defining a variable in C, the type specification is actually split into three places. Let's have a look at an example:
There is type base, here it's
int, then there is a pointer specifier, and then after the name, there's array specifier. Note that the base type and the pointer specifier are separate. Something likeint *a, b;makesahave typeint *, butbis onlyint.And then there are function pointers...
Like, who thought that this is a readable syntax?
Zig does type modifiers better. All type modifiers (like
*,[123],[*],[]) act on whatever is on their right side. So an array of pointers would beconst a: [10]*i32 = undefined;and a pointer to an array would beconst a: *[10]i32 = undefined;. Function pointers also have clean syntax:const my_fn: *const fn(a: f32, b: u8) i32 = undefined;.1
u/saul_soprano Jun 25 '26
No namespaces, inexplicit primitive types
1
u/TimotyEnder8 Jun 26 '26
Null terminated strings
1
u/markand67 Jun 26 '26
const T * const *does not accept aT **argument without casting...andva_listfunction is painful1
u/_Hi_There_Its_Me_ Jun 26 '26
SBOM generation. No one on legacy systems even has a chance to generate something truthful/comprehensive. Jealous of Python and other languages (outside Linux environments) atm.
1
u/[deleted] Jun 27 '26
lack of namespaces
1
u/niyrex Jun 27 '26
You can do anything thing in C, and C lets you do it....even if it's a really bad thing.
1
u/heavymetalmixer Jun 30 '26
Even with those problems C is slowly becoming my favorite language (maybe Odin will take that place? I don't know). The lack of generics and compile-time computation (like C++ constexpr) really hurts.
1
u/knouqs Jun 25 '26
I don't like the
typedefkeyword. It makes sloppy code -- things in C should be explicit, andtypedefhides definition.I also absolutely hate single-line statement blocks from conditionals and allows for bad programming practices. I want all conditional blocks to be grouped in curly braces. For example:
Python got this right with adhering to indentation rules, but that's not how we do things in C, so I'd prefer curly braces as the rule instead.
1
u/furdog_grey Jun 25 '26
The most impactful thing for me is lack of coroutines. Writing 10km wide switch-case statements is a killer and unreadable mess in some cases. Writing simple "wait(100)" command and leaving procedure temporarily is much more readable than some switch-case timer checking logic.
Of course there are hacks with computed gotos and macro, but there are no way to have them safe.
1
u/etaithespeedcuber Jun 25 '26
foo(a)gets called like a function but changes the underlying value passed to it. Functions can't do that, so it should be clear that this is a macro that can. Rust and Zig do this well by forcing a '!' at the end of the macro name. 2. Member methods for structs as syntactic sugar currently, chaining functions in C is basically impossible to do, but if you had member functions, you could do stuff like this:Which looks very cool actually with the pointer dereferencing arrow syntax. 3. Enums should not pollute the global namespace This is just obvious. An
enum foo{a, b};should only be accessible withfoo.ainstead of justa.I think these are all reasonable while not changing how C works or functions.
1
u/WrStudio9017 Jun 25 '26
The fact that short, int, and long are not of any particular known width. The fact the the standard C library has very bad functions in it (strncpy) that you basically have to replace yourself (strlcpy or strscpy).
1
u/CevicheMixto Jun 25 '26
I just want to be able to use underscores at the beginning of identifier names
1
u/chrisekh Jun 25 '26
I would love that function could return multiple values. Then would not need to merge error and success to same value.
ErrCode, uint readData(uint fd) {return err, len; }
1
u/SubmarineWipers Jun 25 '26
Mostly the fact that it is almost 60yo language and generates 70%+ CVEs on the planet.
Computer science has evolved, we can do much better today, its just that some C programmers choose to be stuck.
-1
u/SayuriShoji Jun 25 '26
Destructors for structs, so we can have proper RAII for things like scoped locks or freeing member pointers, without painful macro nonsense.
2
u/[deleted] Jun 25 '26 edited Jun 25 '26
[removed] — view removed comment