simont: A picture of me in 2016 (Default)
simont ([personal profile] simont) wrote2012-03-12 06:52 pm

Yet more C abuse

In two recent posts here, I've suggested moderately evil things to do with the C preprocessor, both on the same theme of defining a macro that can be used like a loop keyword by following its invocation with a statement or block of your choice.

Last week some further thoughts on the subject occurred to me, which were rather more comprehensive and also considerably more evil still. I think I've now taken that general idea to somewhere near the limit of its possibilities, by developing a general system of construction-kit macros that make it more or less feasible for people to develop custom loop types.

The result is far too long to fit in this post, so I've put it up on my website. For those with a strong stomach and an interest in metaprogramming or C abuse or both, I present ‘Metaprogramming Custom Control Structures in C’: http://www.chiark.greenend.org.uk/~sgtatham/mp/.

hairyears: Spilosoma viginica caterpillar: luxuriant white hair and a 'Dougal' face with antennae. Small, hairy, and venomous (Default)

What's the vbKeyCode constant for the {ANY} key?

[personal profile] hairyears 2012-03-12 09:28 pm (UTC)(link)
Thank you: that's not nearly as horrible as I expected it to be...

...Said an Excel developer.

I work on two levels: what's an elegant solution in coding terms; and the ugly questions about how it's actually going to compile and run. The overriding concerns on planet Hairyears are clarity and ease of maintenance - if it was performance, it wouldn't be in VBA! - but sometimes, I need to know what I'm doing, and what's being done for me. And some of *that* is horrible, through and through.

Which in turn means that understanding loops is more than merely coding them, and further reading - like this stuff - is essential.
gerald_duck: (ascii)

[personal profile] gerald_duck 2012-03-12 10:20 pm (UTC)(link)
You mention C++, but surely these shenanigans (fascinating in their twistedness though they may be) belong entirely in the land of C?

In the first place, C++ entirely solves the problem of tidying away resources that go out of scope in a rather more thorough way. And, for that matter, iterators allow non-standard behaviours to be packaged in a for-loop-friendly way. (Even more friendly for C++11's range-based for loops.)

In the second, the combination of exceptions and C++'s somewhat necessary prohibition on jumping past a non-trivial constructor or destructor invocation make the idiom unusable in some cases and dangerous in others.
andrewducker: (Default)

[personal profile] andrewducker 2012-03-13 08:32 am (UTC)(link)

[identity profile] kehoea.livejournal.com 2012-04-02 08:38 am (UTC)(link)
We have a good number of macros that might benefit from this in XEmacs, most of them here. (https://bitbucket.org/xemacs/xemacs/src/0df3cedee9ac/src/lisp.h#cl-1984) (Not the sort of code your average C programmer is that comfortable with, I admit.) Other things are more of a priority at the moment, but I'll bookmark your paper. Thanks!