Live data from Hacker News

Writing C software without the standard library

weeb.ddns.net

61–70 of 188 posts

Re: Writing C software without the standard library

#63
post #3

> Executables are incredibly small (the http mirror server for my gopherspace is powered by a 10kb executable). Is this ever an real issue, even on any embedded system in the last 20 years?

Even if you've got the RAM, it never hurts to improve CPU cache locality.

Re: Writing C software without the standard library

#64
post #4

He claims that your code will be easy to port but then goes straight to Linux system calls. Still I like the idea. This is something that should be covered in a CS 102 type course. I know way to many cs guys who have no idea how to debug, let alone how their is being implemented.

As far as PortableOSIX compliant syscalls are concerned, they are literally portable.

Re: Writing C software without the standard library

#65

Your first paragraph makes me wish this site supported Markdown.

Yeah off topic but if HN supported markdown (and GitHub's flavor of markdown so we could take different types of syntax with their language) would be amazing. There would be a ton more coding examples and discussion, in my opinion, if this were to happen. How do we summon Dang? :)

my netiquette says, more than about three lines of code should go in a pastebin anyway

Re: Writing C software without the standard library

#66

The comment section where gcc puts in ident info can be omitted with -fno-ident and syscall(2) is usually a very thin wrapper[0]. If you follow the musl syscall(2) it simply maps errors to errno[1] and uses the fancy count-args-in-macro[2] to call off the respective $arch/syscall_arch.h[3] syscall$n numbered functions. [0] https://git.musl-libc.org/cgit/musl/tree/src/misc/syscall.c [1] https://git.musl-libc.org/cgit/…

Highly recommend reading the Musl source code if you want to find out how things work. Don't bother trying to look at Glibc.

Cannot agree more.

glibc's source feels like archeology: there's so much history and remnants of bygone eras.

musl feels like a structured, well-engineered and specified piece of architecture.

This isn't a knocj against glibc. But it was grown, not built.

musl and the team's great documentation have been incredibly handy when I've been building tightly constrained applications.

Re: Writing C software without the standard library

#67
post #47
post #42

Earlier quoted context omitted.

True. The OS layer you write (and port to other OSes) is called "the standard library". :-)

A .h file with different syscalls IDs and perhaps a few inline functions is hardly a standard library though

> A .h file with different syscalls IDs

That's not portable even across versions of the same OS, many OS don't support raw syscalls and don't make any guarantees about them. That's why you can't statically link libc on OSX for instance, libSystem is literally the system's interface and necessarily dynamically linked.

Re: Writing C software without the standard library

#69

What is necessary to do this with C++? Is there a tutorial available on the web?

behold the demoscene https://in4k.github.io/wiki/c-cpp

focused on windows, because grafix. also, linux guys are more likely to use C anyway.

I only remember a comment about avoiding exceptions, which I might have read first in the context of micro controllers.

https://www.google.de/search?q=site%3Apouet.net+c%2B%2B+exce...

https://www.google.de/search?q=site%3Apouet.net+c%2B%2B+stdl...

Post reply on HN