Skip to content

Instantly share code, notes, and snippets.

@lucas-mior
Last active October 15, 2023 19:25
Show Gist options
  • Save lucas-mior/f7bde15f780860b40f4a60fb14ea728f to your computer and use it in GitHub Desktop.
Save lucas-mior/f7bde15f780860b40f4a60fb14ea728f to your computer and use it in GitHub Desktop.
C - still no replacement

C - still no replacement

People who design languages can't resist the temptation of doing clever stuff. The result if that we still are having to deal with C problems that could have been solved years ago. Until this is done, we are stuck with this language.

Real issues with C

  • Lack of namespaces
  • Preprocessor is bad
  • Enums don't have explicit integer type
  • Promotion rules are terrible
  • Casts are misleading
  • Having to declare each function before usage
  • historical baggage is confusing:
    • std lib functions with weird types
    • integer types (char, short, int, long...)
    • cryptic standard library names
    • Header files are a mess
    • underline_t types make my eyes bleed
  • more than one way to do simple things
    • increment operator
    • typedef
    • #define vs const vs enum
  • auto formatting for printing is not possible
  • Some forms of UB should be opt-in, like the strict aliasing rule and signed integer overflow. If performance really is affected by those flags, then one should go ahead, activate and fix the bugs.

Minor issues

  • function pointer declaration is bad
  • having to type struct/union all over again when there is no typedef
  • Hidden memory allocations in the standard library
  • Lack of nested functions
  • Anonimous literals require type annotations for any compound type
  • struct/union dereferencing syntax could be using only .
  • lack of tagged unions

Issues with compilers, not the language

  • Too incompatible with one another
  • Idiotic warnings
  • Too much concerned with backwards compatibility
  • Terrible defaults (no warnings)
  • Not transparent enough about UB

Non issues

  • Lack of object oriented programming features
  • Lack of operator overloading
  • Lack of other control flow mechanisms
  • Lack of borrow checker
  • Lack of smart pointers
  • Lack of garbage collector
  • Lack of exception handling
  • Unused variable makes compiler stop (and there is not a way to disable it). What the hell is this?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment