> Principles > Be extremely portable > sp.h is written in C99, and it compiles against any compiler and libc imaginable. It works on Linux, on Windows, on macOS. It works under a WASM host. It works in the browser. It works with MSVC, and MinGW, it works with or without libc, or with weird ones like Cosmopolitan. It works with the big compilers and it works with TCC. > And, best of all, it does all all of that becaus…
sp.h: Fixing C by giving it a high quality, ultra portable standard library
11–20 of 222 posts
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#12Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#13Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#14> Program directly against syscalls Works nicely on Linux where the syscall interface is explicitly stable, but on many (most?) other platforms this is not the case. > There Is No Heap I don't understand what this means, when it's followed by the definition of a heap allocation interface. The paragraph after the code block conveys no useful information. > Null-terminated strings are the devil’s work Agreed! I also fi…
There is a footnote on this saying as much:
> 3. Where “syscall” means “the lowest level primitive available”. On Linux, it’s always actual syscalls. On Windows, that’s usually NT. On macOS, it’s usually the syscall-wrapper subset of libc because you’re forced to link libc and it’s not quite as open as Linux (although there is a rich “undocumented” set of APIs and syscalls that are very interesting).
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#15Earlier quoted context omitted.
Looks like the default allocator uses mmap(2) for every single allocation , which is horribly inefficient - you map a whole PAGE_SIZE worth of memory for every tiny string. Aside from just wasting memory this will make the TLB very unhappy. It looks like sp_log's string formatting is entirely unbuffered which results in lots of tiny write syscalls.
That seems to be a pretty consistent quality level for the entire library. Look at the implementations in sp_math, yikes.
That does spin the meaning of "Sp.h is the standard library that C deserves"
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#16Earlier quoted context omitted.
That seems to be a pretty consistent quality level for the entire library. Look at the implementations in sp_math, yikes.
"How bad can it be, I mean I know that numerics are not many people's strong suit, but..." ... ... ... oh wow, the math functions are really bad implementations. The range reduction on the sin/cos functions are yikes-level. Like the wrong input gives you an infinite loop level of yikes.
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#17I love how hyper-opinionated this is.
When one is competent to work at this level, strong opinions are in order.
Their correctness is something I cannot gage. I'm barely competent to follow the conversation.
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#18> Program directly against syscalls Works nicely on Linux where the syscall interface is explicitly stable, but on many (most?) other platforms this is not the case. > There Is No Heap I don't understand what this means, when it's followed by the definition of a heap allocation interface. The paragraph after the code block conveys no useful information. > Null-terminated strings are the devil’s work Agreed! I also fi…
> Works nicely on Linux where the syscall interface is explicitly stable, but on many (most?) other platforms this is not the case. There is a footnote on this saying as much: > 3. Where “syscall” means “the lowest level primitive available”. On Linux, it’s always actual syscalls. On Windows, that’s usually NT. On macOS, it’s usually the syscall-wrapper subset of libc because you’re forced to link libc and it’s not q…
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#19I agree that pointer and length is better than null-terminated strings (although it is difficult in C, and as they mention you will have to use a macro (or some additional functions) to work this in C).
Making the C standard library directly against syscalls is also a good idea, although in some cases you might have an implementation that needs to not do this for some reason, generally it is better for the standard library directly against syscalls.
FILE object is sometimes useful especially if you have functions such as fopencookie and open_memstream; but it might be useful (although probably not with C) to be able to optimize parts of a program that only use a single implementation of the FILE interface (or a subset of its functions, e.g. that does not use seeking).
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#20I love how hyper-opinionated this is.
Family saying: "It ain't bragging if you can do it." When one is competent to work at this level, strong opinions are in order. Their correctness is something I cannot gage. I'm barely competent to follow the conversation.