Mildly interesting quirks of C
gist.github.com
Mildly interesting quirks of C
1–10 of 91 posts
Re: Mildly interesting quirks of C
#2[deleted]
Re: Mildly interesting quirks of C
#3While a few of these were interesting I'd love to see a short technical explanation of each quirk for the feeble high-level programmer (me). The first one for example, is foo initialised? How so?
Re: Mildly interesting quirks of C
#4"Flat Initializer Lists" is given as an example in K&R C I think, at least the first edition, when writing those extra braces to fill out an initializer must have felt very redundant.
These days many compilers will warn if you do this, however, as it is rare people do this and usually indicates a misunderstanding of the type used.
I think it's quite readable though, so it's a shame it causes warnings. What do you think?
struct { const char *name; int age; } records[] = {
"John", 20,
"Bertha", 40,
"Andrew", 30,
};Re: Mildly interesting quirks of C
#5While a few of these were interesting I'd love to see a short technical explanation of each quirk for the feeble high-level programmer (me). The first one for example, is foo initialised? How so?
I think it's aimed at C programmers. foo is a struct, so it's a type, it's not a variable. The point is just that struct bar is also defined by the definition of struct foo.
Re: Mildly interesting quirks of C
#6Reminds me a bit of "Who Says C is Simple?" written by the people who wrote a C parser & analyser in OCaml (CIL):
https://cil-project.github.io/cil/doc/html/cil/cil016.html
Also: https://cil-project.github.io/cil/doc/html/cil/cil012.html
Re: Mildly interesting quirks of C
#7Are there any practical cases where you'd want "extern void foo"?
Re: Mildly interesting quirks of C
#8 8. Modifiers to array sizes in parameter definitions [https://godbolt.org/z/FnwYUs]
void foo(int arr[static const restrict volatile 10]) {
// static: the array contains at least 10 elements
// const, volatile and restrict all apply to the array type.
}
I imagine most of these depend on the C version, but this one specifically bit me because one tool only supported c99 and the other was c11 or something later.Re: Mildly interesting quirks of C
#9Are there any practical cases where you'd want "extern void foo"?
You could use it for getting an address that will be linked in later. On GCC I get a warning (which I don't think I can mask) for taking the address of such an object, because its expression is type void. A better way of achieving this is usually to declare something like extern unsigned char foo[] instead, but that has a type other than void*.
Re: Mildly interesting quirks of C
#10The top comment in the gist looks like from "Hacker News Parody Thread".