A tale in 3 pictures. In which our hero wonders if he can and doesn't stop to ask if he should.

#c #programming

C preprocessor abuse

C preprocessor abuse. GitHub Gist: instantly share code, notes, and snippets.

Gist
@citizen428 some slight modifications, and you can use cpp -E + that to make a static site generator using the preprocessor.
@necrophcodr Funny you'd say that, because this (`clang -I. -P -E`) but in another context is how this little side quest started.

@citizen428 I mean it has simple uses too, like adding simple include statements in any file, or, as you've shown, macros.

I've used it to make a lockfile for my Containerfile, and I'd just build using cpp -E <file> | docker build -f- <...>

@citizen428

So, it's some kind of chtml...

(you'll definitively want to put the ```#define HTML``` in a .h.tml file included by abuse.c)

@citizen428 I highly recommend combining this with a MAP macro.
@ryanc Please don’t give me ideas πŸ˜‚
@citizen428 Fine. I will not inflict further ideas upon you, but why do you hate fun?
@ryanc I'm just trying to avoid getting nerd sniped into spending any more time on this. I have a much bigger preprocessor abuse planned :D
@citizen428 omg, you even serve it right from C code?! God, I want to unsee this...

@siguza Maximum cursed is what I was going for, so yes. If you prefer CGI and another web server you could use kcgi:

https://kristaps.bsd.lv/kcgi/

kcgi: minimal CGI and FastCGI library for C/C++

A C/C++ library for security-oriented web applications.

@citizen428 Thanks for sharing the code.

In a weird way, this is exactly what the C preprocessor is designed to do.

I still don't want to debug a bigger website though. 

@[email protected] $DEITY no, I'd never want to actually work with this outside of a little late-night hack session.