3 ms·
This one caught my eye: > for example, you must be able to compare two structs using a type-oblivious comparison (e.g., memcmp), so a copy of a struct must ret
by flohofwoe 5y ago
This one caught my eye:
> for example, you must be able to compare two structs using a type-oblivious comparison (e.g., memcmp), so a copy of a struct must retain its padding.
This definitely doesn't work in the real world because the padding bytes will contain random junk which isn't copied along in some situations, depending on the compiler and optimization level.
Also, IMHO what the article calls "low level" might be important for compiler writers, but isn't really all that relevant for most programmers when the comparison is to "high level" languages like Java, C#, Javascript or Python.
In my mind, the most important property of a low level langauge is to provide explicit control over how data is layed out in memory, this is usually an afterthought in high-level languages, if possible at all.
Or more generally: how much explicit control does the language allow before the programmer hits the "manual optimization wall". In that sense C is fairly high level, especially without non-standard extensions, but still much lower level than most other programming languages. I think there is definitely room for more experimental languages between C and assembly.
- rightbyte 5y ago> In that sense C is fairly high level, especially without non-standard extensions, but still much lower level than most other programming languages. In practice you are using gnu c etc. The Stackoverflow consensus that you are supposed to stick to the standard no matter the complexities of the workarounds is rather annoying and seem to be quite prevalent.
- sharpneli 5y agoThe reason for sticking to standard is when inevitably someone will try to compile it with another compiler. It’s far easier just to stick to the spec instead of fixing non standard code. For some reason it has been me several times doing the fixing as original dev thought it’s completely fine. I hope to save others the pain.
- flohofwoe 5y agoIMHO the only practical solution to this problem is to compile and test the code at least on the popular compilers (e.g. GCC, Clang and MSVC), which is quite easy today with CI services like GH Actions. The standard also often doesn't tell what features are actually supported by different compilers (e.g. MSVC famously will never be C99 compliant, but eventually - really soon now! - C11 compliant) - so the language standard is in reality more like a recommendation of what features are more likely to work across compilers than others. Finally, even standard compliant code may still trigger a lot of warnings, and those warnings are different on different compilers or different versions of the same compiler, so testing on different compilers is needed anyway to cleanup warnings.
- pjmlp 5y agoMSVC is already C17 compliant, minus optional annexes.
- deleted 5y ago[deleted]
- int_19h 5y agoIt's not an either-or. Write standard-compliant code as much as possible, and test it with real-world compilers (and work around their quirks or limitations if needed). Somebody trying to compile it 20 years later will thank you.