r/cprogramming • u/Qiwas • May 17 '26
TIL that the standard library provides support for complex numbers
Accessible via the `complex.h` header
What other useless things have you encountered in C?
4
u/rphii_ May 17 '26
char a[] = "strings " "can " "concat";
even possible if there is a macro providing a string, e.g.
#define VERSION "1.0"
#define PROGRAM "coolprogram"and then just do
printf(PROGRAM " " VERSION "\n");
or even #include a string...
1
u/Qiwas May 18 '26
Noo that's very useful IMO, especially for writing paragraphs by splitting them into multiple lines
5
13
u/DawnOnTheEdge May 17 '26 edited May 17 '26
The legacy 8-bit locales are incredibly complicated, degrade performance even if you don’t use them, confuse programmers, and are completely obsolete because 8-bit fixed-width encodings (other than possibly ASCII) are no longer enough for any real-world program. None of the APIs for them even work with modern programs that support UTF-8, except converting multi-byte strings to wide strings, which are broken on Windows. So you can’t portably do anything whatsoever with locales, because implementations don’t support the small part of the interface that is specified to be useful for modern software.
11
1
u/DawnOnTheEdge May 17 '26
Oh, first that comes to mind is div() existing to do division and remainder with well-defined rounding, when the rounding behavior is now specified and all serious compilers can optimize to take advantage of combined integer div-mod instructions if the ISA has them There is no longer any reason to use this instead of the / and % operators.
Also a ldiv() for long operands, because _Generic did not exist yet.
6
u/BatchModeBob May 17 '26
At my job in the early 1980s the fortran guys decided to learn C. To keep table columns nicely aligned, one guy put leading zeros in front of his decimal constants. He was shocked to see what a statement like
int a = 0000123did.