{"id":7682,"date":"2026-07-18T00:01:55","date_gmt":"2026-07-18T07:01:55","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7682"},"modified":"2026-07-11T12:27:06","modified_gmt":"2026-07-11T19:27:06","slug":"what-the-heck-is-this","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7682","title":{"rendered":"What the Heck is This?"},"content":{"rendered":"<p>As I plow the digital seas, I often come across a piece of programming flotsam worthy of investigation. Most of it is obfuscated C, which is delightful. The obfuscated code that outputs something wonderful is most entertaining. But every so often I stumble upon something perplexing like the following code:<br \/>\n<!--more--><\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2026_07_18-Lesson.c\" rel=\"noopener\" target=\"_blank\">2026_07_18-Lesson.c<\/a><\/h3>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n\r\nint typedef[[]]$;\r\n\r\nint main($[[]]$)\r\n{\r\n    [[]]$:&amp;&amp;$&amp;&amp;$&amp;&amp;puts(\"hello world\");\r\n\r\n    return 0;\r\n}<\/pre>\n<p>Seriously?<\/p>\n<p>For starters, at Line 3, should <em>typedef<\/em> be the first item? What is <em>int typedef<\/em>? And then what is the <em>typedef<\/em> defining?<\/p>\n<p>The code can build, but not under any circumstances, which I&#8217;ll get into shortly. Here is the output:<\/p>\n<pre>hello world<\/pre>\n<p>So, nothing fancy is going on other than code clutter that somehow doesn&#8217;t affect the <em>puts()<\/em> function &mdash; though it looks like it does.<\/p>\n<p>First, this code does not build under <em>clang<\/em>:<\/p>\n<pre>0718.c:3:13: error: expected expression\r\nint typedef[[]]$;\r\n            ^\r\n0718.c:5:12: error: expected expression\r\nint main($[[]]$)\r\n           ^\r\n0718.c:5:15: error: expected ')'\r\nint main($[[]]$)\r\n              ^\r\n0718.c:5:9: note: to match this '('\r\nint main($[[]]$)\r\n        ^\r\n0718.c:5:11: warning: omitting the parameter name in a function definition is a C2x extension [-Wc2x-extensions]\r\nint main($[[]]$)\r\n          ^\r\n0718.c:7:2: error: expected expression\r\n        [[]]$:&&$&&$&&puts(\"hello world\");\r\n        ^\r\n1 warning and 4 errors generated.<\/pre>\n<p>The weird code builds under <em>gcc<\/em> with three warnings:<\/p>\n<pre>2026_07_18-Lesson.c:5:5: warning: \u2018main\u2019 takes only zero or two arguments [-Wmain]\r\n    5 | int main($[[]]$)\r\n      |     ^~~~\r\n2026_07_18-Lesson.c: In function \u2018main\u2019:\r\n2026_07_18-Lesson.c:7:15: warning: the address of \u2018$\u2019 will always evaluate as \u2018true\u2019 [-Waddress]\r\n    7 |         [[]]$:&&$&&$&&puts(\"hello world\");\r\n      |               ^~\r\n2026_07_18-Lesson.c:7:21: warning: value computed is not used [-Wunused-value]\r\n    7 |         [[]]$:&&$&&$&&puts(\"hello world\");\r\n      |<\/pre>\n<p>All these warnings and errors make sense, until you accept the second item worth mentioning:<\/p>\n<p>This code adheres to the C23 standard. Using the <code>-std=c23<\/code> switch works for both <em>clang<\/em> and <em>gcc<\/em>.<\/p>\n<p>To untie the knots, start with the <em>typedef<\/em>:<\/p>\n<p><code>int typedef[[]]$;<\/code><\/p>\n<p>The result of this statement is that the dollar sign is declared as an integer identifier: <code>$<\/code> == <em>int<\/em>. Remember that the $ character isn&#8217;t used as an operator in C. But what&#8217;s happening here involves two tricky things.<\/p>\n<p>The first is that <code>[[]]<\/code> is used as attribute syntax in the C23 standard. In a way, it works like an empty set of parentheses, so it&#8217;s ignored in the code (under C23).<\/p>\n<p>The second thing happening is a quirk in the <em>gcc<\/em> compiler that accepts this type of backwards <em>typedef<\/em> definition. This exploit allows <em>typedef<\/em> to replace <em>int<\/em> as an identifier, though the result isn&#8217;t used elsewhere in the code. So, after all the dust settles, the <code>$<\/code> identifier now means <em>int<\/em><\/p>\n<p>The <em>main()<\/em> function uses this as its argument: <code>$[[]]$<\/code><\/p>\n<p>In this obfuscation, the <code>[[]]<\/code> thing is ignored, so the declaration is <code>$<\/code> of the type <em>$<\/em>. As <em>main()<\/em> has arguments by default, what&#8217;s captured here is the <em>argc<\/em> value, or integer count of items present at the command line, which is always a positive, non-zero value. The value is used in Line 7, which is also hideous:<\/p>\n<p><code>[[]]$:&amp;&amp;$&amp;&amp;$&amp;&amp;puts(\"hello world\");<\/code><\/p>\n<p>The <code>[[]]<\/code> thing is ignored in C23 as an empty attribute.<\/p>\n<p><code>$:<\/code> is a label named <code>$<\/code>, which is the argument count from the <em>main()<\/em> function. As the label isn&#8217;t referenced, I think it&#8217;s just here for decoration and obfuscation.<\/p>\n<p>The next few characters are parsed like this:<\/p>\n<p><code>&amp;&amp;$ &amp;&amp; $ &amp;&amp;<\/code><\/p>\n<p>The <code>&amp;&amp;$<\/code> is a <em>gcc<\/em> extension to obtain the address of a label, <code>$<\/code>.The result is an integer, not a pointer.<\/p>\n<p>The <code>&amp;&amp;<\/code> is a logical AND. It&#8217;s compared with <code>$<\/code>, which is the value of the <em>main()<\/em> function&#8217;s argument.<\/p>\n<p>The final <code>&amp;&amp<\/code>; evaluates the return value of the <em>puts()<\/em> function, which is non-negative. The entire expression evaluates as TRUE, though nothing acts upon this result.<\/p>\n<p>Weird.<\/p>\n<p>Bottom line: This code is obnoxiously obfuscated. It takes advantage of C23 as well as peculiarities with the <em>gcc<\/em> compiler. I avoid obfuscation in my code as much as possible, but I do take delight in unweaving puzzles such as this example.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Time to unravel some C language obfuscation I found on the Interwebs. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7682\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-7682","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7682"}],"version-history":[{"count":6,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7682\/revisions"}],"predecessor-version":[{"id":7690,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7682\/revisions\/7690"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}