Live data from Hacker News

Writing C software without the standard library

weeb.ddns.net

31–40 of 188 posts

Re: Writing C software without the standard library

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

Portability is impossible without the standard library.

Re: Writing C software without the standard library

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

These are nowadays supported by Windows and few BSDs too, who needs more portability than that :)

Re: Writing C software without the standard library

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

Well, it is hard to see an alternative to that outside supplying your own OS with the library...

Re: Writing C software without the standard library

#34
post #11

Earlier quoted context omitted.

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 t…

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 design is perhaps less common in demo software, but certainly plausible in embedded products which at least try to be somewhat optimized.

Re: Writing C software without the standard library

#36
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

#37
post #11

Earlier quoted context omitted.

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 t…

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?

[deleted]

Re: Writing C software without the standard library

#38
I think this is unnecessary when you got :

    typedef unsigned long int  u64;
    typedef unsigned int       u32;
    ...
if you define your own types like this you may need to revise them when you switch architecture or even compiler.

Now you could argue that this is part of the standard library, but I actually see it as a part of the standard C language.

Re: Writing C software without the standard library

#39
post #31
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.

Portability is impossible without the standard library.

What ? You just write your OS layer for each platform and it's portable.

Re: Writing C software without the standard library

#40
post #29

Earlier quoted context omitted.

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

But still, Linux syscalls are different on each architecture.

Indeed, stupidly different. Different syscall numbers, different argument orders, different values for constants, different struct layouts, ... Some architectures, like MIPS, are particularly bad, with nods to Irix compatibility thrown in.

The BSDs are all exactly the same for every architecture, sane.

Post reply on HN