Live data from Hacker News

A header-only C implementation of C++

github.com

61–70 of 94 posts

Re: A header-only C implementation of C++ <algorithm>

#61
post #51

Earlier quoted context omitted.

> Ah, one of those "generic" libraries back from MS-DOS days. Nothing about this screams "MS-DOS".[1] Why the disparagement? [1] I know, I was programming at that time.

pjmlp is a C++ fan who consistently criticizes C.

Git repo of user filters (https://news.ycombinator.com/item?id=33365189) seems inevitable

Re: A header-only C implementation of C++ <algorithm>

#62

Earlier quoted context omitted.

Honestly, who cares? On a more constructive side, I think adding some value by giving the poster some feedback or engaging in a conversation about the topic would be nice, otherwise it just sounds as an attempt to show off. I'm not a fan of these "header only" projects nor am I a fan of overly clever code because even though it's fun and rewarding to write it's not a great fit for larger or collaborative projects whe…

> attempt to show off Why not? rurban's work is solid and should be shown off.

I think it's not polite, if you just want to show something cool you did you could create your own thread. You don't interrupt a street musicians and start playing in front of the crew just because you think you are a "better" artist or that your version of the song is cooler right? It's common courtesy.

On a side note, I looked at both codebases and even though I've already said that I wouldn't use either of them I have to say that I find rurbans to be somewhat messier and uglier so I have to disagree with you.

Re: A header-only C implementation of C++ <algorithm>

#63

Earlier quoted context omitted.

> attempt to show off Why not? rurban's work is solid and should be shown off.

I think it's not polite, if you just want to show something cool you did you could create your own thread. You don't interrupt a street musicians and start playing in front of the crew just because you think you are a "better" artist or that your version of the song is cooler right? It's common courtesy. On a side note, I looked at both codebases and even though I've already said that I wouldn't use either of them I…

Your attitude may apply to some situations, but in general preliminary judgements kill innovation. Next time after reading your comment, someone somewhere may remain silent without showing off their art, and the world will be missing the next Copernicus, Gauss, Wozniak, Stroustrup.

If I have to choose between "polite" and "innovation", I choose "innovation" any time of day. This is the same kind of difference as to "diss" someone for no real reason as opposed to letting someone just be and "blossom" so they could share their enlightenment with everyone, and thus benefit us all.

Re: A header-only C implementation of C++ <algorithm>

#66
Nice work! Have you considering combining ARRAY_ALG_TYPE and ARRAY_ALG_PREFIX into a single function-like macro? ARRAY_ALG_TYPE_PREFIX(int, intv_), for example, can set up all the other macros. I would also recommend adding a ARRAY_ALG_ prefix to the NAME1, NAME2, NS, and T macros so that you don't redefine any previous macros with these names.

Re: A header-only C implementation of C++ <algorithm>

#67
post #51

Earlier quoted context omitted.

> Ah, one of those "generic" libraries back from MS-DOS days. Nothing about this screams "MS-DOS".[1] Why the disparagement? [1] I know, I was programming at that time.

pjmlp is a C++ fan who consistently criticizes C.

Correction,

pjmlp is a security fan who consistently criticizes C.

Re: A header-only C implementation of C++ <algorithm>

#68

Why header only? Jesus christ, we have a linker.

If I am right, in C, it is not possible to implement fast type-safe generic algorithms without stuffing everything in headers. libc's qsort can be implemented in a separate .c file but it is a lot slower than std::sort as a result.

Re: A header-only C implementation of C++ <algorithm>

#69
post #46

Earlier quoted context omitted.

> you can't drive your tooling Can you suggest what tooling actually can help to implement algorithms and data structures libraries with generic types in a clean way?

The issue here is people too lazy to tell their compiler where to find a header file so instead they cook up a bespoke system that is specific to every library using this approach.

That is not why this project is header-only. It's so you can include it multiple times to produce multiple specialized types; it has to be header-only so it can produce a series of structs and functions for each specialized type into your compilation unit, with the compiler separately checking each produced specialization. You configure it before including using a series of preprocessor defines. It's a common way to handle generic types in C.

This can't be a single separate compilation unit that you link in; the generic specialization doesn't work that way. You seem to be talking about libraries that are header-only purely for convenience but this is not one of those projects.

With a library like this, you'd want to have one .c file in your project that produces all the implementations for your specialized types, then link that with the rest of your project. From a quick look at the doc, this project supports this.

Re: A header-only C implementation of C++ <algorithm>

#70
post #16

Well, I do like mine better, which is closer to the STL, and for all containers. https://github.com/rurban/ctl/

I think our projects are completely different and don't have the same goals. 1. You don't implement the most important algorithms. For example `stable_sort` for arrays. So right there, it's not even a substitute. One of my motivations from the start was simply to have `stable_sort` in C (to implement database queries). 2. Yours is a clever implementation of C++ features using macros. But it's not idiomatic C. If some…

Arguable void* is the more idiomatic C implementation, but as you said in the README, compilers still have trouble optimizing this (mostly due to bad decisions regarding function cloning).
Post reply on HN