4 ms·
How useful is C without platform or environment specific frameworks or libraries in most cases?
by scarface74 5y ago
How useful is C without platform or environment specific frameworks or libraries in most cases?
- tialaramex 5y agoIt's almost completely useless without libraries. It's probably a tough call whether to just write assembly language instead at that point, if you have a nice assembler and know how to use it that might be more productive than C with no libraries. Much of the stuff programmers are just used to being "part of C" is actually from a library. For example NULL is just a macro that some library provided, C's "null pointers" are just the literal zero for a pointer, even if your hardware does not represent "null pointers" by an all-zeroes value.
- pjmlp 5y agoCase in point, malloc() is impossible to implement in ISO C, it is either done in Assembly, or requires language extensions. Unless we are speaking about the very niche use case of allocating a big blob of static memory on the global segment. Most of the stuff done with ISO C + language extensions/external Assembly, can be as easily done in safer languages. Language extensions and external Assembly aren't a C priviledge.
- tialaramex 5y agoWell, an allocator is something your system might just not need. Rust doesn't come with an allocator either, if I only have say 16384 bytes of RAM maybe I don't want an allocator, I can write down what I'm using each byte for. But C doesn't come with functions like memcmp() and memcpy() or memmove() either and those are pretty fundamental even if you're on a tiny constrained system that can't aspire to stuff like "strings" and "allocation" you've probably heard of data structures and copying.
- BenjiWiebe 5y agoWhy can't you implement malloc() in ISO C? Or do you mean you can't write your own malloc that complies with the OS's memory management in C? Because I'm pretty sure you can write a malloc in ISO C when you aren't dealing with an OS (which is usually when you need to write a malloc).
- remexre 5y agoDon't you run into issues with strict aliasing? Same deal as it being impossible to implement BSD sockets in ISO C because of the sockaddr funny business.