I would recommend a double switch for the %A-Z parser switch(format++) and then switch(format++) for the second level this way you don't need a elif chain, did this for my print system.
I often hear people say something along the lines of, "Why are you bothering to write X? There's this library already." And sometimes that's correct, but sometimes it sounds like, "Why bother playing Chopin's Etudes? There are plenty of recordings of them already."
Sometimes you just want to practice your craft and learn stuff.
Sometimes you have looked inside that library and were not delighted by what you found.
Sometimes, you have an idea of how to do it better.
I think we're by and large glad that Linus did not listen to, "Why write an operating system? We've got plenty of them already, they work fine."
Any collection of functions (and data) that you don't write yourself.
E.g., there are compilers that actually have intrinsic functions for highly optimized memcpy() functions (they generate code that is optimized for alignment). Still library (even more: that's libc specific!).
Your use of __builtin_trap() is such an example (and probably not needed)
__builtin comes from the compiler, do your research before posting, it's the same thing as <stddef.h>, <stdbool.h>, and <stdint.h> and which are actually from the compiler and can be used freeestanding
4
u/Willsxyz Dec 22 '25
Good start. Now implement the printf().
2
u/TheTrueXenose Dec 23 '25
I would recommend a double switch for the %A-Z parser switch(format++) and then switch(format++) for the second level this way you don't need a elif chain, did this for my print system.
Edit: nice start do :)
13
u/MisterHarvest Dec 23 '25
That is cool!
I often hear people say something along the lines of, "Why are you bothering to write X? There's this library already." And sometimes that's correct, but sometimes it sounds like, "Why bother playing Chopin's Etudes? There are plenty of recordings of them already."
I think we're by and large glad that Linus did not listen to, "Why write an operating system? We've got plenty of them already, they work fine."
1
u/tobdomo Dec 30 '25
No library? Where do you think your __builtin stuff comes from?
1
u/Sosowski Dec 22 '25
You can’t just ignore variadic arguments. This is UB and can corrupt your stack
1
u/Wise_Reward6165 Dec 23 '25
Next you need to write out arrays, variables, objects and the rest of basic C
1
u/Intelligent-Turnup Dec 25 '25
Nice... Better than I can currently do.
1
u/Key_River7180 Dec 30 '25
Pretty cool! You could also make it in C with inline assembly (__asm__ volatile("<my assembly>")), and also this (GCC/Clang-only trick):