Fun with macros (and syntax) in C

This is just a funny post I want to share…just for fun.

I’m really annoyed by languages that are C syntax-like with all the parentesis (and there are people that hates Lisp) and curly braces (function declaration). What I hate the most is to always have to press “shift” for this charactes.

return_type function_name "(" args ")" "{"
   function_body
"}"

Of course, you can use any template system/plug-in of your editor of choise that automatically does this for you, but it takes a long time to master this, and, eventually you forgot to use it and end up writing the whole thing…

Also…There is the comment stuff that you need to add those // or (/* and */). That’s super annoying…

/*
   Here goes a long comment you will never read...
*/

So, I though..“how can I transform the C syntax into something more ‘cleaner’?”

First things first, let’s clean up the function declaration and let’s borrow some ideas from older languages like BASIC.

Here is our new main function:

#define declare (
#define begin   ){
#define end     {

int main
declare
    int count,
    char* args[]
begin
    return 0;
end

Not so bad, actually. With a proper syntax highlight this may looks kinda “nice”.

Now, let’s try to make comments a little bit more palatable.

#include <stdio.h>

#define declare (
#define begin   ){
#define end     }
#define doc(a...)

doc(This is kinda nice,
    but unfortunately we lost all quotes...)
int main
declare
begin
  return 0;
end

It’s silly, but a really nice exercise on macro in C.