| ▲ | duckqlz an hour ago | ||||||||||||||||
“Types.c” is dangerous code to bring to every project. f32/64 makes assumptions about the platform. Worse yet, the macros at the bottom are all functionally incorrect. Macros like MIN/MAX need to be contained in parentheses to avoid precedence errors. For example, we take `Min(x,y)` from the code. Consider what happens if I write `ans = 2 * Min(3,4)` because of the way Min is defined that will expand to `ans = 2 * 3 < 4 ? 3 : 4` and while you may expect ans to be 3 it will infact resolve to 4. Subtle bugs like these can creep into code and cause really hard to debug errors. Finally, while u32 is a little faster to type than `uint33_t` it makes the project harder to read forcing the reader to learn the author’s personal c dialect. While it is a stylistic choice, I can’t see why anyone would want to sacrifice code highlighting and expressiveness for slightly less verbosity | |||||||||||||||||
| ▲ | flohofwoe an hour ago | parent | next [-] | ||||||||||||||||
It is totally fine for C code to make "assumptions about the platform". I'm not sure where this obsession with non-existing or irrelevant target platforms is coming from that might be theoretically supported by the C standard, but are not relevant in the real world except for niche use cases which the library author might not care about (like some extremely limited embedded CPUs). E.g. not every C library needs to support every target platform just because that target platform has a C compiler, and all code (not just C code) should be considered broken anyway until it is actually tested on a specific platform (and in that case any problems that show up are trivial to fix). You're right about the macro thing of course. The typedef-thing is arguable, I would at least try to not let such custom typedefs over basic types leak into the public API of the library where they could collide with typedefs of other libraries (e.g. all public types of a library should have at least a prefix which makes name collisions with other libraries unlikely). | |||||||||||||||||
| |||||||||||||||||
| ▲ | kazinator 30 minutes ago | parent | prev [-] | ||||||||||||||||
> f32/64 makes assumptions about the platform. Indeed, but, by the way, those are assumptions that some newer languages now make about the entire world. | |||||||||||||||||