Paul on Nostr: TIL: Constant folding in C is a GCC extension (though it works in LLVM / clang), ...
TIL: Constant folding in C is a GCC extension (though it works in LLVM / clang), therefore you can't do something like this:
const int STATUS_SUCCESS = 1;
switch (status) {
case STATUS_SUCCESS:
The joys of the difference between const, a constant expression, and what can be determined at compile-time (it's clearly possible to fold the constant at compile-time, but presumably not portable).
#C
Published at
2026-05-29 12:02:27 UTCEvent JSON
{
"id": "8555236d3ea91581667df1bab48e6f37858aa18a59d5484c99e33cc6f4d77244",
"pubkey": "841863febf01dcb24f5abdb8d137ff157f77922a00fac24c2ed7a0362d48f254",
"created_at": 1780056147,
"kind": 1,
"tags": [
[
"t",
"c"
],
[
"proxy",
"https://social.xk7.net/users/pwaring/statuses/116657759711442872",
"activitypub"
],
[
"client",
"Mostr",
"31990:6be38f8c63df7dbf84db7ec4a6e6fbbd8d19dca3b980efad18585c46f04b26f9:mostr",
"wss://relay.ditto.pub"
]
],
"content": "TIL: Constant folding in C is a GCC extension (though it works in LLVM / clang), therefore you can't do something like this:\n\nconst int STATUS_SUCCESS = 1;\n\nswitch (status) {\n case STATUS_SUCCESS:\n\nThe joys of the difference between const, a constant expression, and what can be determined at compile-time (it's clearly possible to fold the constant at compile-time, but presumably not portable).\n\n#C",
"sig": "f1099e8730a51d9f39bf3d07136e01a2f75a8e387d21a4ef33e13d37e316db570dd882e1b629a2c0774d8d23b302fe408b1ba16df69ea214e2de90d4ad5f6c94"
}