Liste des Groupes | Revenir à cl c |
On 07/01/2025 20:32, Julio Di Egidio wrote:<snipped>
In particular, I am using C90, and compiling with
`gcc ... -ansi -pedantic -Wall -Wextra` (as I have
the requirement to ideally support any device).
People who say they want their code to run on anything are invariably wildly exaggerating.:) I do have embedded, and FPGAs, and even transpiling to e.g. Wasm, etc. in mind, my overall idea for now simply being: as long as the device comes with a C compiler that is not too broken. (I am also planning to distribute source files only: it also makes my life and coding so much easier, at the cost of not being able to "micro-optimize": where I am rather hoping that optimization can still come down the line if needed as an added pre or post processing step.)
People who say they want to write strictly standards-conforming code, especially C90, so that it will run everywhere, misunderstand the relationship between the C standards and real-world tools.So, now that I have qualified it with "any device coming with a C compiler (that is not too broken)", would you think coding it in "ANSI C" makes some sense?
I would say that the most portable language standard to use would be a subset of C99. Avoid complex numbers, VLAs, and wide/multibyte characters, and it will be compilable on all but the most obscure compilers. The use of <stdint.h> types make it far easier to write clear portable code while keeping good efficiency, and many C99 features let you write clearer, safer, and more efficient code. C90 was probably a good choice for highly portable code 15-20 years ago, but not now. (Your use of "malloc" eliminates far more potential devices for the code than choosing C99 ever could.)Assuming I don't in fact care if and how well a compiler does its job (in fact my policy for now is: as long as it compiles with GCC with those flags), what is wrong with "malloc"?
When you have a function with a parameter of type "const T * p", this tells people reading it that the function will only read data via "p",Never mind, it's a private (static) method, so I am not "lying" to anybody: rather const and cast and almost everything in C is altogether something else...
Les messages affichés proviennent d'usenet.