15

LOL that's why I love C!

The function pointer cast for strcmp because qsort expects a compare function with two const void * pointers instead of two const char * pointers, that's just beautiful.

Not to mention the hack to abuse strcmp on a struct - which just works because the first struct member is a string and the rest just gets swapped with memcpy as opaque data.

I guess that wouldn't pass a code review at work. :-)

Comments
  • 1
    Beautiful, functional travesty.
  • 0
    @rendezvous It's more that a code review should give a WTF on this construct, hopefully. Sure it works without undefined behaviour, but the maintainability of a codebase like this may have limits. ;-)
  • 0
    @Fast-Nop technically these operations are considered undefined behavior, no?
  • 1
    @beegC0de
    nope they are not
  • 0
    @beegC0de No because char * can alias anything so that this won't run pointer aliasing.

    @Haxk20 That's the beauty of C when it isn't crippled by junior friendly coding standards. ^^
  • 0
    @Haxk20 Well I like it because it's quite rare that a function pointer cast is required, makes sense and is even possible in the first place.
Add Comment