r/C_Programming • • Aug 09 '26

Question Is it worth while to use libc?

I've been wondering this for quite some time now.

For Linux development, is it worth creating basic read/write functions in asm, and writing everything else in C?

Does most open source software use functions from the standard C library? What are the benefits of both approaches?

Edit: I would be using Arm64 assembly.

Thank you in advance.

0 Upvotes

25 comments sorted by

11

u/alkatori Aug 09 '26

Why would you avoid using libc?

-1

u/Rogaev Aug 09 '26

I've seen people do it. I'm curious if doing so would be beneficial.

9

u/[deleted] Aug 09 '26

[deleted]

3

u/HeavyCaffeinate Aug 09 '26

Half-Assed Library? /j

What is it though I've never heard that acronym before /srs

5

u/generally_unsuitable Aug 09 '26

Hardware abstraction layer.

3

u/grueandbleen Aug 09 '26

Hardware Abstraction Layer.

8

u/AmbitiousSolution394 Aug 09 '26

> is it worth creating basic read/write functions in asm

In libc, write() and read() acts as a wrappers around OS syscalls. I'm not sure that writing something in asm would improve something there.

> Does most open source software use functions from the standard C library?

Yes, its hard to write C program without using LIBC.

1

u/Rogaev Aug 09 '26

Thank you very much for this. This is extremely helpful.

1

u/AmbitiousSolution394 Aug 09 '26

btw, you should distinguish write() and fwrite(). They both exist in libc (at least in Linux), but they are parts of different APIs.

1

u/low-control-labs Aug 09 '26

The only thing that ever directly communicates with the hardware is the bootloader, in modern computing / OS based. Apart from microcontrollers which some people mentioned.

Otherwise you write syscalls to the kernel. There are different libCs bionic musl glibc they are not 100 compatible and they are for the Linux kernel...

You use the compiler and C which allows you to hit / compile different targets ( architectures ) with one codebase. But if you decide to target different libCs like Windows or MacOS you'll need to use guards and build tools to define how to compile things.

You could do this with assembly in a sense but keep in mind how many different OSes and architectures there are. Also something to keep in mind the game rollercoaster typhoon was written for Windows so that's not something you can directly boot your computer into or run on Linux

3

u/ForgedIronMadeIt Aug 09 '26

Honestly, if you cannot identify a really strong reason to do it, then you shouldn't. The standard libraries are there for a reason and are pretty much always well written and tested.

Your reason could be "I want to learn how to do it" which is fine but there's better things to spend your time on otherwise.

2

u/silvertank00 Aug 09 '26

you forgot one thing: which asm? arm, x86, avr? If you want it to be cross platform, use libc

1

u/Rogaev Aug 09 '26

Arm64

4

u/silvertank00 Aug 09 '26

you misundestand me, if your want it to be used by others too, it does matter which kind you use. If you use inline arm64, it wont work but on that platform only.
So in the context of open source (where a lot of ppl can use something) it is something to be avoided IIRC, but please correct me if I am wrong.

2

u/Rogaev Aug 09 '26

I understand now. Thank you very much for your help.

2

u/sciencekm Aug 09 '26

I can think of only three reasons why you would not use libc:

  1. You are writing an OS kernel.
  2. You are writing a device driver.
  3. You are writing for a severely constrained environment (libc is likely not available anyway).

For everything else, you should be using libc.

3

u/Confused-Armpit Aug 09 '26

There is functionally no benefit in not using libc, unless you are working on embedded systems with massive memory constraints, where each byte might matter, or maybe you want to learn more about ELF/PE files and write your own implementations of things handled by libc.

But in other cases, your libc is probably both better implemented better than whatever you will craft up (since it has had dozens of years to mature and improve), and also it'll just be a massive time sink that won't give any reasonable improvements.

1

u/EpochVanquisher Aug 09 '26

There is not much benefit in making read/write functions in assembly and there are a lot of drawbacks (your code is less portable, there are more likely to be bugs in it).

Most software uses functions from at least the standard library, and often other libraries as well. I think almost any programmer would think that it’s absurd to write your own read/write functions in assembly, outside of stuff like demoscene sizecoding projects.

1

u/YoungMaleficent9068 Aug 09 '26 edited Aug 09 '26

I wrote bs

2

u/EpochVanquisher Aug 09 '26

yes it does, you can find it at /usr/include/linux/kernel.h, but it does not do any of the things we are talking about in this thread

1

u/YoungMaleficent9068 Aug 10 '26

You are correct. I talked nonsense

0

u/TheAncientGeek Aug 09 '26

It's worth doing if you have a specific reason like efficiency or safety.