3 ms·
> In general, when working in C I avoid the standard library, libc, as much as possible. If possible I won’t even link it. Completely agree: freestanding C is
by matheusmoreira 4y ago
> In general, when working in C I avoid the standard library, libc, as much as possible. If possible I won’t even link it.
Completely agree: freestanding C is a superior language. I'm so happy to discover I'm not alone in thinking like this. The author is very thorough in his criticism of libc, I learned a lot from the post.
> The platform code is small in comparison: mostly unportable code, perhaps raw system calls, graphics functions, or even assembly.
For me this is what made programming fun again! I don't even bother with multiplatform implementations anymore, I go straight for Linux system calls. Turns out to be a much better interface compared to libc.
> On some platforms it will still link libc anyway because it’s got useful platform-specific features, or because it’s mandatory.
If anyone would like to know why such a thing would be mandatory, I began writing about this subject literally just a few days ago.
https://www.matheusmoreira.com/linux/system-calls https://www.matheusmoreira.com/linux/system-calls
Still very much a work in progress but it does provide context for his claim.
- jcalvinowens 4y ago(Shamelessly plugging my own project) It's sort of amazing how little userspace code a crude webserver using Linux syscalls can be: https://github.com/jcalvinowens/asmhttpd https://github.com/jcalvinowens/asmhttpd One 4K page of code! No stack!
- stefanos82 4y agoAmazing job mate! +1 How much traffic can it handle, have you benchmark it?
- agumonkey 4y agohighly readable, kudos
- jmholla 4y agoThat's real neat. I was messing around with it an threw together this Dockerfile for a tiny server container. Just mount the desired folder to `/http`: FROM alpine as build RUN apk add --no-cache build-base gcompat nasm RUN mkdir /src COPY \* /src RUN cd /src \ && make FROM scratch COPY --from=build /src/asmhttpd /asmhttpd CMD ["/asmhttpd", "/http"] (Run: `podman build -t $IMAGE .; podman run -p 8080:80 -v $PATH:/http -d $IMAGE`)
- matheusmoreira 4y agoThat's awesome.
- drpixie 4y agoAgree. The vast majority of complaints about C are actually complaints about the standard library. It's library - if you don't like it, use something better :)