mos_8502 :verified: on Nostr: Stupid C Tricks: Here's a fun one. Check out this snippet:<code>#pragma ...
Stupid C Tricks:
Here's a fun one. Check out this snippet:<code>#pragma once<br><br>__attribute__((transparent_union))<br>typedef union {<br> Widget widget_value;<br> DrawingArea drawing_area_value;<br> Label label_value;<br>} AnyWidget;<br></code>
See that attribute, "transparent_union"? That means a couple of things, but most importantly, it means that a function argument which is declared as that union type can take an argument value of any of the types in the union without casting; the local variable in the function will be of the union type.
Published at
2024-04-13 00:33:07Event JSON
{
"id": "ae8952100b94883a6ba6767d6d591e1395a46520201722329d1e01f7ff3afe1b",
"pubkey": "04f8915424c713657ad6ce59443d28dbdcf5832687c9af560ae388f59276a137",
"created_at": 1712968387,
"kind": 1,
"tags": [
[
"t",
"pragma"
],
[
"proxy",
"https://studio8502.ca/users/mos_8502/statuses/112261096236454914",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://studio8502.ca/users/mos_8502/statuses/112261096236454914",
"pink.momostr"
]
],
"content": "Stupid C Tricks:\n\nHere's a fun one. Check out this snippet:\u003ccode\u003e#pragma once\u003cbr\u003e\u003cbr\u003e__attribute__((transparent_union))\u003cbr\u003etypedef union {\u003cbr\u003e Widget widget_value;\u003cbr\u003e DrawingArea drawing_area_value;\u003cbr\u003e Label label_value;\u003cbr\u003e} AnyWidget;\u003cbr\u003e\u003c/code\u003e\n\nSee that attribute, \"transparent_union\"? That means a couple of things, but most importantly, it means that a function argument which is declared as that union type can take an argument value of any of the types in the union without casting; the local variable in the function will be of the union type.",
"sig": "0adfa371fea84bdfde0acff70bf3088fbf026e876d5248e1dfdab0b5b065d07a26d859c12e4cd04df2d0101237192ca6845c4fb1e22e4d965d49f68b48e8b747"
}