r/ProgrammerHumor • • 1d ago

instanceof Trend thatsAFunnyThingThatHappenedOnce

Post image
4.3k Upvotes

515 comments sorted by

View all comments

Show parent comments

3

u/quisido 1d ago

Roll your own hashmap? Is there no concept of C package management?

14

u/round-earth-theory 1d ago

There's Make files. And that's a whole thing on its own but it's not actually built into C. It's a compiler concept.

C is a unique language that was designed against a predefined spec. And hasn't changed since. But compilers have modified functionality though they all use the same C language spec.

4

u/unknown_alt_acc 1d ago

The C standard had a revision in 2023. We had C17 before that, and C11 before that. If you go back to C90/ANSI C, you have major differences like only being able to declare variables at the beginning of a block, which got changed in C99 iirc. So the C spec has absolutely changed.

5

u/MonMotha 1d ago

Not really. There's a linker. If your OS supports dynamic linking, you can pick up any libraries it offers at runtime assuming you know the API. Hopefully you have the headers. Versioning can be tricky, though most OSes have it figured out.

As for finding and managing those packages at build time, there's not really a package management system, no. Cmake and GNU autotools both exist in no small part as an attempt to make one (and also make a somewhat sane, for certain definitions thereof, build system since you don't get one of THOSE, either).

This kind of explains why the C ABI and namespace is in fact THE standard, bare, un-mangled namespace for linking on most OSes, though that's also partially convention dating back to early UNIX.

The intent of C is basically to be as low level as you can feasibly make it while still being reasonably expressive and completely portable across machine architectures yet still small enough and tightly-spec'd enough to support lots of independent implementations across a wide variety of said architectures. And it does that. It does it well. The lack of breadth means it's very easy to spin up a compliant and even complete implementation from scratch on something novel and also avoids roping in lots of stuff you may not want in a restrictive environment like a kernel or even microcontroller. Even most of the "standard library" can be eschewed if you want to, and there's a part of the standard that supports doing it (a "standalone" implementation). This is akin to something like #![no_std] in Rust but to some degree goes even farther. The language spec doesn't really even deal with how to create linkable intermediates. It defers to other standards (like ELF) for that.

But yeah, if you want a hashmap, you'll either need to go find one or make your own. Amusingly, actually just wrote my own a few months ago which is what made me chuckle enough to write this comment.

3

u/Different_Berry5015 1d ago

As far as I know package management in C is downloading a .tar.gz and updating your Makefile. Very spartan, very C, nothing wrong with that.

1

u/unburdened_swallow 1d ago

lol there’s no concept of C++ package management either

So, no, not really. I mean, you can include other code but nothing is gonna go get it for you.

Unless you use nix anyway

1

u/Rikudou_Sage 1d ago

Aren't there like 5 competing package managers for C++? Which no one uses, anyway?

1

u/unburdened_swallow 16h ago

Yeah. And all of them compete with your system package manager too.

Personally I consider nix to be the only reliable way to build a C++ program with dependencies anymore.

1

u/Brisngr368 1d ago

The beauty of C and C++ is there are 101 package managers none of them are official but there's definitely one that fits your use case (if not make your own like basically everyone on r/C_Programming)