Live data from Hacker News

Writing C software without the standard library

weeb.ddns.net

11–20 of 188 posts

Re: Writing C software without the standard library

#11

This is required if you do systems programming (e.g: kernel development).

Or demo coding on old hardware. I sometimes write demos for the Atari ST (68000-based home computer launched in 1985), and the modern way of doing that is to develop on a modern computer, and cross-compile to a native ST executable.

The main loops are all assembler, but the support code is in C, but the C code is used as a more expressive assembler, and linking with libc requires way too much memory.

All this means that I don't even have things like memcpy() available. In a way it's a quite liberating way to program, since you are in full control of the hardware.

I guess yesterday's computers is today's embedded hardware.

Re: Writing C software without the standard library

#15
post #9
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?

AVR atmega based devices generally have about 2kb SRAM, and 32kb flash. Maybe 2kb EEPROM.

This is true, but the stdlib provided by the compilers aimed at these chips is usually very bare bones and size-optimized to begin with. So it's likely hard to save much space by reimplementing subsets of it.

Re: Writing C software without the standard library

#16
post #15
post #9

Earlier quoted context omitted.

AVR atmega based devices generally have about 2kb SRAM, and 32kb flash. Maybe 2kb EEPROM.

This is true, but the stdlib provided by the compilers aimed at these chips is usually very bare bones and size-optimized to begin with. So it's likely hard to save much space by reimplementing subsets of it.

True, but you often end up avoiding parts of the stdlib like malloc anyway, because they tend to be heavy handed on the board.

(I've never needed to remove stdlib yet).

Re: Writing C software without the standard library

#17

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

You can get surprisingly far without using libc's malloc/free. E.g. TeX, the typesetting system by Knuth, implements its own dynamic memory handling. It has a large static array of bytes, and allocates from that when needed.

Re: Writing C software without the standard library

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

> He claims that your code will be easy to port but then goes straight to Linux system calls.

Many linux developers believe "code is portable" means "can run on different linux distros".

Edit: To be fair, he said architectures, and i think he meant CPU architectures, i.e. AMD64 and i386.

Re: Writing C software without the standard library

#19

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 reading things harder and waste unnecessary resources on bling and fluff with all those javascript frameworks slowing them down, pagination often being replaced with "endless scrolling" which makes it hard not only to skip large bits of content but also hard to see how much content is there in the first place. And of course the newest worst trend of all - using an entire web browser as a UI framework for a text editor (i mean honestly, how people decided that HTML and CSS are the best technologies to use as the foundation for user interfaces?).

The only bit i'd disagree would be with games, at least on AAA games since i have some experience there and -at least at the engine level- there is still a lot of low level wizardry being done there.

Re: Writing C software without the standard library

#20
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?

It's not a real issue, no.

It's a statement of one's professional competency.

Post reply on HN