Live data from Hacker News

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

github.com

11–20 of 50 posts

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

#11

Earlier quoted context omitted.

I've done a share of C metaprogramming with the preprocessor myself, and have dealt a lot with other peoples' C metaprogramming. I've also seen people use pages of algrebra as a substitute for a couple lines of calculus. I struggled for years with a soldering iron, always frustrated by bad solder joints. Then, I discovered a Weller thermostat controlled iron, and get a perfect joint every time. Not everyone knows the…

Your experience soldering is a much better response. You present a concrete suggestion for use a weller thermostat controlled iron. But you did not present a concrete suggestion for an alternative to the C pre-processor. You could do this with C++ templates, for instance. But the LESS and SWAP operations may or may not get inlined. With the C pre-processor you can be certain that the operations get inlined, since no…

> But you did not present a concrete suggestion for an alternative to the C pre-processor.

If someone asked, I would. But since I do have a dog in that hunt, I felt it would be more appropriate for others to make a suggestion, as there are several.

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

#12

Earlier quoted context omitted.

I've done a share of C metaprogramming with the preprocessor myself, and have dealt a lot with other peoples' C metaprogramming. I've also seen people use pages of algrebra as a substitute for a couple lines of calculus. I struggled for years with a soldering iron, always frustrated by bad solder joints. Then, I discovered a Weller thermostat controlled iron, and get a perfect joint every time. Not everyone knows the…

Your experience soldering is a much better response. You present a concrete suggestion for use a weller thermostat controlled iron. But you did not present a concrete suggestion for an alternative to the C pre-processor. You could do this with C++ templates, for instance. But the LESS and SWAP operations may or may not get inlined. With the C pre-processor you can be certain that the operations get inlined, since no…

[deleted]

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

#13
post #10

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

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

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

#14
Along the same lines, I use Christopher Swenson's sort.h at https://github.com/swenson/sort/

  You get the choice of many sorting routines, including:

    Timsort (stable)
    Quicksort
    Merge sort (stable)
    In-place merge sort (not stable)
    Shellsort
    Binary insertion sort
    Heapsort
    Selection sort (this is really only here for comparison)
    Grail sort (stable)
    Sqrt Sort (stable, based on Grail sort, also by Andrey Astrelin).

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

#15

Earlier quoted context omitted.

I've done a share of C metaprogramming with the preprocessor myself, and have dealt a lot with other peoples' C metaprogramming. I've also seen people use pages of algrebra as a substitute for a couple lines of calculus. I struggled for years with a soldering iron, always frustrated by bad solder joints. Then, I discovered a Weller thermostat controlled iron, and get a perfect joint every time. Not everyone knows the…

Your experience soldering is a much better response. You present a concrete suggestion for use a weller thermostat controlled iron. But you did not present a concrete suggestion for an alternative to the C pre-processor. You could do this with C++ templates, for instance. But the LESS and SWAP operations may or may not get inlined. With the C pre-processor you can be certain that the operations get inlined, since no…

> But the LESS and SWAP operations may or may not get inlined.

True. But modern inliners are pretty good, and if they can't inline it due to its complexity, it's pretty unlikely it'll be faster.

Note the performance comparison in the article.

Low level hand-optimizations paid off handsomely in the 1980s, but are usually best left to the compiler's optimizer these days.

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

#16
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

just last night i was thinking how cool it would be for an IDE plugin that expands rust macros for easier grokking. now i need one for your #defines, lol

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

#17

Earlier quoted context omitted.

Your experience soldering is a much better response. You present a concrete suggestion for use a weller thermostat controlled iron. But you did not present a concrete suggestion for an alternative to the C pre-processor. You could do this with C++ templates, for instance. But the LESS and SWAP operations may or may not get inlined. With the C pre-processor you can be certain that the operations get inlined, since no…

> But the LESS and SWAP operations may or may not get inlined. True. But modern inliners are pretty good, and if they can't inline it due to its complexity, it's pretty unlikely it'll be faster. Note the performance comparison in the article. Low level hand-optimizations paid off handsomely in the 1980s, but are usually best left to the compiler's optimizer these days.

SIMD being an exception still (unless maybe Intel compiler + C/C++ + proper annotations)

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

#18

Earlier quoted context omitted.

Your experience soldering is a much better response. You present a concrete suggestion for use a weller thermostat controlled iron. But you did not present a concrete suggestion for an alternative to the C pre-processor. You could do this with C++ templates, for instance. But the LESS and SWAP operations may or may not get inlined. With the C pre-processor you can be certain that the operations get inlined, since no…

> But the LESS and SWAP operations may or may not get inlined. True. But modern inliners are pretty good, and if they can't inline it due to its complexity, it's pretty unlikely it'll be faster. Note the performance comparison in the article. Low level hand-optimizations paid off handsomely in the 1980s, but are usually best left to the compiler's optimizer these days.

The article is talking code and demonstrating results.

Talk is cheap, show the code!

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

#19

Earlier quoted context omitted.

> But the LESS and SWAP operations may or may not get inlined. True. But modern inliners are pretty good, and if they can't inline it due to its complexity, it's pretty unlikely it'll be faster. Note the performance comparison in the article. Low level hand-optimizations paid off handsomely in the 1980s, but are usually best left to the compiler's optimizer these days.

The article is talking code and demonstrating results. Talk is cheap, show the code!

Parent comment is by the inventor of D, among other things…

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

#20

Earlier quoted context omitted.

Your experience soldering is a much better response. You present a concrete suggestion for use a weller thermostat controlled iron. But you did not present a concrete suggestion for an alternative to the C pre-processor. You could do this with C++ templates, for instance. But the LESS and SWAP operations may or may not get inlined. With the C pre-processor you can be certain that the operations get inlined, since no…

> But you did not present a concrete suggestion for an alternative to the C pre-processor. If someone asked, I would. But since I do have a dog in that hunt, I felt it would be more appropriate for others to make a suggestion, as there are several.

Oh come on, Walter, don't make us beg... Show us how you'd do it in D to achieve the exact same result.
Post reply on HN