3 ms·
with C people choose to use macros and define blocks because they want to, but it doesn't have to be done that way if you don't think that's fun. (Pushing back
by fsckboy 3y ago
with C people choose to use macros and define blocks because they want to, but it doesn't have to be done that way if you don't think that's fun. (Pushing back on choice of "fun"ness) Macros and define blocks turn into C code anyway.
I think those header files festooned with ifdef's are a nightmare, and it's the wrong choice, a type of premature optimization.
- djbusby 3y agoI'm familiar with various methods - and also what we observe in the wild across many FOSS projects. The #define, #ifdef, macro method is in the majority of what I see. And the examples of the "right way" are harder to find (now I wonder what GPT would suggest). None of those methods are fun for me anymore :(
- fsckboy 3y agoI was simply pointing out that complaining about the C preprocessor is not complaining about C. You don't have to use the C preprocessor, you can do what it does in C, because that's what it does.
- tendto 3y agoI agree it's possible to use C. Arguably C still lacking a better way of including files is a limitation of C as a language instead of only a complain on the preprocessor.
- unwind 3y agoJust to add some clarification, I think what you mean is that one alternative way is to split implementations apart where necessary, and have separate translation units for various targets. That can lead to a cleaner implementation without conditional compilation (or with conditional compilation restricted to picking the right files). What other method(s) were you thinking of?
- fsckboy 3y ago> What other method(s) were you thinking of? runtime conditional configuration anything Rust can do, C can do, C can even implement Rust. I'm not saying that you shouldn't prefer Rust, I'm sure it has nice features, i was just trying to clarify confusion about what C "requires" you to do. People use a lot of define blocks, but I don't. It's a throwback to wanting to minimize code size at compile time from back when that was important.