Skip to content

Comment on CPIP – A C/C++ preprocessor implemented in Pythonparent

Comments

I have found (and let me qualify, I am by no means an old hand at this) that macros allow you to do a degree of metaprogramming beyond just being "dumb enums" that makes them powerful on their own. I'm half expecting to be struck down where I stand for this next statement on account of some fine point I'm not aware of, but aspects of modern languages; decorators in python, serve similar functionality to what I used to use macros in C for. I think there's certainly room for the preprocessor going forward, although it may be valuable to ask, as python has, can we make it more elegant/idiomatic/coherent with the language as a whole. C macros, when you get "involved" are... arcane.

macros allow you to do a degree of metaprogramming

I think this comment would be more believable if you provided some examples. Since you didn't, let me provide one and then hopefully you (or someone else) can provide more.

http://journal.stuffwithstuff.com/2012/01/24/higher-order-ma...

I would provide a summary, but I think you can get a hint just from the URL. (Actually, the URL is misleading. The title of the blog post is "Higher Order Macros in C++".)

I'll admit, I didn't write the comment with the expectation that it would be attacked on believability, but I'll try to give a satisfactory response:

The definition of metaprogramming is "the writing of computer programs that with the ability to treat programs as their data", which #defines can certainly do, and which decorators in a slightly different sense also do. I hate to just drop Wikipedia links, but it says it far better than I could, and contains an example of using C style macros to do templated metaprogramming. (http://en.wikipedia.org/wiki/Metaprogramming)

This is all wrong actually. Modern C++ lets you do AST type stuff without this macro nonsense.

Really? That's awesome! How??

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.