{"path": "/posts/fun-with-macros-in-c/", "title": "Fun with macros (and syntax) in C · Bruno Dias", "html": "<!doctype html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"utf-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <meta name=\"description\" content=\"Fun with macros (and syntax) in C\">\n  <title>Fun with macros (and syntax) in C · Bruno Dias</title>\n  <link rel=\"canonical\" href=\"https://diasbruno.github.io/posts/fun-with-macros-in-c/\" data-post-metadata>\n  <meta name=\"author\" content=\"Bruno Dias\" data-post-metadata>\n  <meta property=\"og:type\" content=\"article\" data-post-metadata>\n  <meta property=\"og:title\" content=\"Fun with macros (and syntax) in C\" data-post-metadata>\n  <meta property=\"og:url\" content=\"https://diasbruno.github.io/posts/fun-with-macros-in-c/\" data-post-metadata>\n  <meta property=\"article:published_time\" content=\"2019-01-13T01:28:21+00:00\" data-post-metadata>\n  <link rel=\"icon\" href=\"/assets/site/signature.svg\" type=\"image/svg+xml\">\n  <link rel=\"alternate\" type=\"application/atom+xml\" title=\"diasbruno\" href=\"/atom.xml\">\n  <link rel=\"alternate\" type=\"application/json\" href=\"/posts/fun-with-macros-in-c/content.json\">\n  <link rel=\"stylesheet\" href=\"/assets/site/tokens.css\">\n  <link rel=\"stylesheet\" href=\"/assets/site/site.css\">\n  <link rel=\"stylesheet\" href=\"/assets/site/footer.css\">\n\n</head>\n<body class=\"light\">\n<div id=\"site-page\">\n<a class=\"skip-link\" href=\"#content\">Skip to content</a>\n<header class=\"site-header\">\n  <a class=\"brand\" href=\"/\" data-site-navigation aria-label=\"Bruno Dias, home\">\n    <img src=\"/assets/site/signature.svg\" width=\"24\" height=\"34\" alt=\"\">\n  </a>\n  <nav aria-label=\"Main navigation\">\n    <ul>\n<li><a class=\"nav-vrn\" href=\"/vrn/\" data-site-navigation><span class=\"nav-label\">vrn</span> <span class=\"nav-badge\">research</span></a></li>\n<li><a class=\"nav-posts\" href=\"/posts/\" data-site-navigation aria-current=\"location\">Posts</a></li>\n<li><a class=\"nav-projects\" href=\"/projects/\" data-site-navigation>Projects</a></li>\n<li><a class=\"nav-about\" href=\"/about/\" data-site-navigation>About</a></li>\n</ul>\n  </nav>\n</header>\n\n<main class=\"section\" id=\"content\" tabindex=\"-1\">\n  <article class=\"post-detail\">\n    <header class=\"section-header\">\n      <p class=\"post-category\">Post</p>\n      <h1>Fun with macros (and syntax) in C</h1>\n\n      <p><time datetime=\"2019-01-13T01:28:21+00:00\">2019-01-13</time></p>\n    </header>\n    <div class=\"post-columns\">\n      <section class=\"post-body\" aria-label=\"Article\">\n\n<p>This is just a funny post I want to share&hellip;just for fun.</p>\n\n<p>I&rsquo;m really annoyed by languages that are C syntax-like with all\nthe parentesis (and there are people that hates Lisp)\nand curly braces (function declaration). What I hate the most\nis to always have to press &ldquo;shift&rdquo; for this charactes.</p>\n\n<pre><code>return_type function_name \"(\" args \")\" \"{\"\n   function_body\n\"}\"\n</code></pre>\n\n<p>Of course, you can use any template system/plug-in of your editor of choise\nthat automatically does this for you, but it takes a long time to master this,\nand, eventually you forgot to use it and end up writing the whole thing&hellip;</p>\n\n<p>Also&hellip;There is the comment stuff that you need to add those <code>//</code> or (<code>/*</code> and <code>*/</code>).\nThat&rsquo;s super annoying&hellip;</p>\n\n<pre><code>/*\n   Here goes a long comment you will never read...\n*/\n</code></pre>\n\n<p>So, I though..&ldquo;how can I transform the C syntax into something more &lsquo;cleaner&rsquo;?&rdquo;</p>\n\n<p>First things first, let&rsquo;s clean up the function declaration and let&rsquo;s borrow\nsome ideas from older languages like BASIC.</p>\n\n<p>Here is our new main function:</p>\n\n<pre><code>#define declare (\n#define begin   ){\n#define end     {\n\nint main\ndeclare\n    int count,\n    char* args[]\nbegin\n    return 0;\nend\n</code></pre>\n\n<p>Not so bad, actually. With a proper syntax highlight this may looks kinda &ldquo;nice&rdquo;.</p>\n\n<p>Now, let&rsquo;s try to make comments a little bit more palatable.</p>\n\n<pre><code>#include &lt;stdio.h&gt;\n\n#define declare (\n#define begin   ){\n#define end     }\n#define doc(a...)\n\ndoc(This is kinda nice,\n    but unfortunately we lost all quotes...)\nint main\ndeclare\nbegin\n  return 0;\nend\n</code></pre>\n\n<p>It&rsquo;s silly, but a really nice exercise on macro in C.</p>\n\n      </section>\n      <aside class=\"post-links\" aria-labelledby=\"post-links-heading\">\n        <h2 id=\"post-links-heading\">Links</h2>\n        <ul>\n<li><a href=\"/posts/\" data-site-navigation>All posts</a></li>\n        </ul>\n      </aside>\n    </div>\n  </article>\n</main>\n\n<footer class=\"site-footer\">\n  <div class=\"site-footer-inner\">\n    <a class=\"site-footer-home\" href=\"/\" data-site-navigation>Bruno Dias</a>\n    <ul aria-label=\"Footer links\">\n      <li><a href=\"https://github.com/diasbruno\">GitHub</a></li>\n      <li><a href=\"/atom.xml\">Atom feed</a></li>\n    </ul>\n  </div>\n</footer>\n\n</div>\n<script type=\"module\" src=\"/assets/site/navigation.js\"></script>\n</body>\n</html>\n"}
