News for hackers. Stuff that matters.
Re:The tiniest C sort function? by jacquesm on Tuesday January 12, 2010 @03:10PM (#1048386)
If you program in this style you are simply asking for trouble.

C is a great little language but I've seen it be described as a racecar. Take too many turns on two wheels and you'll end up regretting it.

There is absolutely no benefit from trying to cram something like this in to two lines other than to show off your C fu, it sets a bad example and and makes for very obscure bugs.

A defensive programming style with clarity in mind rather than weird little optimizations like this are a great way to get good mileage out of what is essentially a luxury assembler.

The lower the level of the language you are working the more important clarity is. As soon as you start to rely on obscure language features or possibly even implementation dependent tricks you clearly no longer have the mindset required for long term maintainable code.

Of course it is a fun little exercise but it really is an example of exactly how not to program in C.

Incidentally, this code will only compile on C99 standard compilers and even then it will probably give you a warning or two about missing return types.

Re:The tiniest C sort function? by ajross on Tuesday January 12, 2010 @03:38PM (#1048462)
Must you be so humorless? It's a clever hack, designed to show how little syntax is required to capture a given algorithm. The admonishment against programming style seems silly: no one actually does that for anything that needs to be maintained (at least no one who can write a correct selection sort). Lighten up, basically.
Re:The tiniest C sort function? by jacquesm on Tuesday January 12, 2010 @03:43PM (#1048477)
> no one actually does that for anything that needs to be maintained

You wish.