Live data from Hacker News

Writing C software without the standard library

weeb.ddns.net

71–80 of 188 posts

Re: Writing C software without the standard library

#71

The guy is definitely a fan of old-school minimalism: http://weeb.ddns.net/0/articles/modern_software_is_at_its_wo... I have to say I miss the old days of Gopher, too. It was so much easier to focus on the content back then.

Member when webpages were all content and no ads?

Re: Writing C software without the standard library

#72

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? :)

Code coloration wouldn't be that useful (if the snippets are that long they should probably go in a separate pastebin or a proper repository, reddit's comments do just fine without)

On the other hand backslash escaping (the lack of it and emphasis clusterfuck drives me nuts), block quotes, inline code/monospace and links I really miss.

Section titles, lists and tables would be nice as well, though not deal breakers.

Considering the maintainers have repeatedly refused to make any improvement to comment formatting in almost 10 years since HN was created, I'm not holding my breath though, it's obvious nobody cares about comment authorship and craft.

Re: Writing C software without the standard library

#73
post #34

Earlier quoted context omitted.

I'm curious what the use case of memcpy is in highly-optimised software. Are there any scenarios where copying bytes is better than using a char*+length tuple?

There can be hardware-driven requirements that force you to simply have data in a particular place in memory, and if you want that data to hang around you might need to manually move it somewhere else. There's also the case where your API accepts a pointer and a size, but you don't want to have lingering pointers into the caller's memory, so you have to copy the data over to the "inside" of the API. This kind of desi…

That is exactly it. For example, on the Atari ST you display graphics by copying the bitmaps to the screen address.

Much of the C code is used during precomputation of data before the actual time-critical code is run. This involves copying lots of data in order to set it up so that as little computation as possible is performed in the actual time-critical parts.

Re: Writing C software without the standard library

#74
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.

I've written Windows programs without the std library. The Win32 has plenty of replacement functions you can use instead though so it's much less work than what's presented here.

You get the same sorts of benefits though.

Re: Writing C software without the standard library

#75

The guy is definitely a fan of old-school minimalism: http://weeb.ddns.net/0/articles/modern_software_is_at_its_wo... I have to say I miss the old days of Gopher, too. It was so much easier to focus on the content back then.

I find myself agreeing with him 100%. Not just on Gopher (although i did write a Gopher client some time ago - http://runtimeterror.com/tools/gopher/ ) but on the entire rant about wasting resources, UIs that waste screen real estate and become unusable in smaller resolutions, fonts that only look good with anti-aliasing and have weird misplaced pixels with antialiased disabled (which i also do), websites that make r…

> (although i did write a Gopher client some time ago - http://runtimeterror.com/tools/gopher/)

I keep meaning to finish up my Gopher Client and release it upon the world...

https://www.weegeeks.com/upload/Jar-Gopher-Browser-Full-Scre...

Re: Writing C software without the standard library

#76
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.

[deleted]

Re: Writing C software without the standard library

#77
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.

When I was learning C, I loved Plauger's book on the standard library for just that reason; it's very informative to be guided through the implementation of the whole thing, not only to see how it works, but it's also a good way just to be introduced to everything in it without any magic. It's an excellent 2nd book on C, I think.

Re: Writing C software without the standard library

#78
post #74
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.

I've written Windows programs without the std library. The Win32 has plenty of replacement functions you can use instead though so it's much less work than what's presented here. You get the same sorts of benefits though.

Win32 is itself a layer on top of the syscalls, and already provides much of the functionality of the C standard library.

Re: Writing C software without the standard library

#79

Fantastic until you need to malloc. You're reimplementing libc, but at least you know what's going on at every level.

Unless you also need to free, it's pretty simple.

Also easy if your free/malloc is just a wrapper around munmap/mmap.

Re: Writing C software without the standard library

#80
A value in the range between -4095 and -1 indicates an error, it is -errno.

The syscall/errno stuff has always seemed unusual, inelegant, and inefficient --- instead of just returning a negative error code directly, the function returns the vague "an error has occurred" -1, and you have to then check errno separately after that. It only adds insult to injury when you realise that the kernel itself isn't doing it, but the syscall wrappers. And thanks to POSIX standardising this mechanism, the alternative will likely never get much adoption; of course, if you write your own syscall wrappers like this article, then you can skip that bloat.

For now this guide is linux-only, but I will be writing a windows version when I feel like firing up a virtual machine.

Unfortunately the Windows syscalls are not officially documented and even less stable than on Linux, changing even between service packs.

http://j00ru.vexillium.org/ntapi/

http://j00ru.vexillium.org/ntapi_64/

At least on Linux the first few (i.e. the oldest, most common and useful) syscalls have not really moved around over the years:

https://filippo.io/linux-syscall-table/

Post reply on HN