A very surface change (almost syntactic sugar) that would be neat for me is some form of generics. Specifically, to allow me to implement an algorithm once for different data types. Right now I do it with preprocessor macros and includes; it works but feels wrong.
Going deeper, but not as far as changing the language (not hoping for memory safety here), I would like better research and documentation for undefined behavior (UB).
I'm not completely opposed to UB. I understand it is an unfortunate performance/safety trade-off that's not fully avoidable in a historical language like C. However, there are many types of UB, and for a few of them, the performance benefits feel theoretical (not supported by empirical evidence). I would love some before/after benchmarks with the types of UB that can be disabled in the compiler, and some open-minded discussion afterwards.
I'm not sure if that horse could ever be put back in the barn, but I think my mindset for using C would probably feel a lot different if somehow it could be made a strict subset of C++.
The default behavior for a case within a switch statement should be to break. If you want to fall through to the next case, it should have been an explicit command (e.g. fallthrough).
switch(x)
{
case 1: DoSomething();
case 2: DoSomethingElse();
case 3: SomePrep();
fallthrough;
case 4: DoMore();
default: DoNothing;
}
Only one statement needed to have case 3 fall through to case 4. No breaks needed at the end of any other cases.
get rid of Macros
adopt Pascal style pointer references... @ is an address, p^ is what p points to
adopt some form of counted strings, with a null on the end for compatibility
adopt Pascal style cast statements, with each path being exclusive (default break)
[+] [-] stncls|2 years ago|reply
Going deeper, but not as far as changing the language (not hoping for memory safety here), I would like better research and documentation for undefined behavior (UB).
I'm not completely opposed to UB. I understand it is an unfortunate performance/safety trade-off that's not fully avoidable in a historical language like C. However, there are many types of UB, and for a few of them, the performance benefits feel theoretical (not supported by empirical evidence). I would love some before/after benchmarks with the types of UB that can be disabled in the compiler, and some open-minded discussion afterwards.
[+] [-] DLA|2 years ago|reply
[+] [-] Shawnj2|2 years ago|reply
[+] [-] logicalmonster|2 years ago|reply
[+] [-] didgetmaster|2 years ago|reply
switch(x) { case 1: DoSomething(); case 2: DoSomethingElse(); case 3: SomePrep(); fallthrough; case 4: DoMore(); default: DoNothing; }
Only one statement needed to have case 3 fall through to case 4. No breaks needed at the end of any other cases.
[+] [-] mikewarot|2 years ago|reply
[+] [-] bjourne|2 years ago|reply
[+] [-] AlectronikLabs|2 years ago|reply
Then, second for namespaces.
[+] [-] tsukikage|2 years ago|reply
[+] [-] sigsev_251|2 years ago|reply
[+] [-] jjgreen|2 years ago|reply
[+] [-] AnimalMuppet|2 years ago|reply
[+] [-] mytailorisrich|2 years ago|reply
[+] [-] pestatije|2 years ago|reply
[+] [-] akasakahakada|2 years ago|reply
don't;
know;