Live data from Hacker News

Qsort.h – Quicksort as a C macro (2019)

github.com

41–50 of 50 posts

Re: Qsort.h – Quicksort as a C macro (2019)

#41

If you're doing metaprogramming using the C preprocessor, it's time to move to a more advanced language.

You're right, but also famously an interested party in the promotion of one of these "more advanced languages".

People often take bias to mean that a source is false or untrustworthy and I think this is a nice counterexample.

Re: Qsort.h – Quicksort as a C macro (2019)

#43
On one hand, neat.

On the other hand, I think it's sad that so much time and brainpower is going on contriving ways to get bad tooling to do something, rather than on the actual meat of the problem solving.

You'd think that in 50 years somebody could have invented a better preprocessor, and save the need for all the while(0) and other trickery needed for macros.

Re: Qsort.h – Quicksort as a C macro (2019)

#44

If you're doing metaprogramming using the C preprocessor, it's time to move to a more advanced language.

C is still the King of languages.

Almost, it is the prince of memory corruption bugs, the throne belongs to Assembly.

Re: Qsort.h – Quicksort as a C macro (2019)

#45
post #25

Today I learned that for modern processors, quicksort code is small enough that the compiler can inline them if the definition is visible during compilation. See here for comparison of isort function implemented using plain static functions vs the macro in TFA: https://godbolt.org/z/arGjPGhKE . It's not as flexible as the macro form (not being able to pass two arrays at once like the sortByAge example in TFA), but I…

Did you try inline as well? Why are they not as flexible as the macro? Couldn't the swap not also process two arrays?

Re: Qsort.h – Quicksort as a C macro (2019)

#46

Earlier quoted context omitted.

I wrote one back in 1983 or so for 16 bit DOS, too! A few years later, I was at a C++ conference where they asked me to sit on an "Ask us anything" panel. I was there along with the developers of Microsoft C, Borland C, etc. The first question was "do you still ship a version of your compiler that will run on a floppy disk system?" Vendor 1 said sure, and launched into a long description of how the files could be shu…

Wow, in 1983 I hadn’t even seen a hard disk in person!

I had one back then, but I did say "a few years later...".

Re: Qsort.h – Quicksort as a C macro (2019)

#47
I like C a lot. One big advantage of the language is that its complete syntax and standard runtime functions can fit in one brain.

That said, I hate the way a lot of programmers use the preprocessor. For me, macros should be just simple expressions or functions (i mean they sohould be invokeable like functions) . But very often, there's a lot of magic inside macros, making them hard to use, let alone understand.

Re: Qsort.h – Quicksort as a C macro (2019)

#48
post #45
post #25

Today I learned that for modern processors, quicksort code is small enough that the compiler can inline them if the definition is visible during compilation. See here for comparison of isort function implemented using plain static functions vs the macro in TFA: https://godbolt.org/z/arGjPGhKE . It's not as flexible as the macro form (not being able to pass two arrays at once like the sortByAge example in TFA), but I…

Did you try inline as well? Why are they not as flexible as the macro? Couldn't the swap not also process two arrays?

The function is already inlined because the implementation is visible. You can check the assembly, it has no calls to the compare and swap functions.

I guess you're right, since the function accepts a void pointer, it could also point to an array of two array pointers. So yes, it can also process two arrays.

Re: Qsort.h – Quicksort as a C macro (2019)

#49
post #10

Earlier quoted context omitted.

Maybe they don't want to move to a more advanced language, maybe they want to mess around with the C preprocessor. :)

If you want to show cleverness, by all means! I still use some primitive tools, and know there are better alternatives, but I'm not going to defend sticking with them. BTW, I did win the Obfuscated C contest one year, and (naturally) used the preprocessor: https://www.ioccc.org/1986/bright/bright.c

Must... resist... being... nerdsniped... oh no too late, now I have to figure out what it's doing without looking it up. :D I've never entered the OCCC but I've read a bunch of past entries and always wanted to enter someday.

Re: Qsort.h – Quicksort as a C macro (2019)

#50

Earlier quoted context omitted.

About a year ago I had a look at a C compiler for 16bit computers, featured in disk form on I think Adrian's digital basement YT channel. The compiler was very basic, nothing like you'd expect from a compiler even from the dragon book. So simple and it was a production compiler too! Sadly I can't remember the name of it to reference here.

I wrote one back in 1983 or so for 16 bit DOS, too! A few years later, I was at a C++ conference where they asked me to sit on an "Ask us anything" panel. I was there along with the developers of Microsoft C, Borland C, etc. The first question was "do you still ship a version of your compiler that will run on a floppy disk system?" Vendor 1 said sure, and launched into a long description of how the files could be shu…

What versions did you offer otherwise? I don't recall CD becoming popular on computers until the 90s.
Post reply on HN