Yet more C abuse [entries|reading|network|archive]
simont

[ userinfo | dreamwidth userinfo ]
[ archive | journal archive ]

Mon 2012-03-12 18:52
Yet more C abuse
LinkReply
[personal profile] gerald_duckMon 2012-03-12 22:20
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.
Link Reply to this | Thread
[personal profile] simontMon 2012-03-12 23:38
I mention C++ mostly because there exists at least one compiler which hasn't yet got round to supporting C99 – but that compiler does support C++. So if you're prepared to write code in the common subset of C99 and C++ (which mostly just means adding a few explicit casts from void *), then you can do this sort of thing even when one of the compilers you have to support is that one.

It's true, of course, that if you're writing a program that's actually allowed to use C++ features then you probably want to be doing an entirely different set of horrifying language abuses :-)
Link Reply to this | Parent
navigation
[ go | Previous Entry | Next Entry ]
[ add | to Memories ]