4 ms·
C is not a difficult language. I know a lot of electronic engineers that know how to program in C but don't know a thing about informatics, for example what is
by alerighi 5y ago
C is not a difficult language. I know a lot of electronic engineers that know how to program in C but don't know a thing about informatics, for example what is DNS, or what is JSON, or how to access a FTP server, and things like that. But they know how to program their microcontrollers in C.
> C programmers need to learn about many different forms of UB: https://blog.regehr.org/archives/1520 https://blog.regehr.org/archives/1520. Most take years to learn these rules. Many never learn them.
UB really don't care that much in real life. When you are targeting a particular platform, that for most C programmer is some sort of 8/32 bit microcontroller, the only thing you care is the datasheet of the microcontroller. Of course you do things that in general are undefined behavior, but in the particular case lead to a perfectly predictable result.
In reality you only have to care about UB if your goal is to share code between hardware platform. But let's be realistic, most of the time you don't. Even if you do, some UB are these days standardized, for example integer overflow is UB, in practice you know that on every architecture 2 complement arithmetic is used and thus is well defined.
The real problem is that compiler for a misinterpretation for the standard started treating UB as "you are allowed to do whatever stupid thing you want since the condition will never happen", that is the real problem. In reality if you compile without optimization and with flags that avoid this stupid decisions it's not a problem.
> Most real world C programs use some nonstandard language extensions on some target platforms. C learners trying to read production code have to navigate these.
Again, it's a problem only if you are targeting different hardware platforms. But if you only program on ST microcontrollers (for example) why should you care?
And you must use them in some situations, for example in C there is not a way to control how a struct is packed (to decode efficiently data from a serial connection for example you define a packed structure and access individual fields). Or inline assembly is not in the standard (what if you need to use an instruction of the microcontroller that is not exposed by the C library?).
> The C compilation and linking model is complicated and platform dependent. Compilation is a major stumbling block for students who have to learn Make or CMake at the same time they learn C.
It's. But most of the time you stuck on whatever the development environment for the target hardware platform is setup to. Most C programmers doesn't even know what CMake or Make is, I care about it and do things by hand, most other people use IAR or Keil or whatever proprietary software that integrates compiler, build system and IDE.
- Zababa 5y agoI think your post highlights perfectly why I think we should talk about the roles of C and not C itself. The C you talk about seems to be a very different beast compared to the C people write and use when building shared libraries that are used across a wide variety of platforms. For example, the people writing OpenSSL would have very different concerns from the people you talk about.
- jolux 5y agoCompilers are allowed to do whatever they want when encountering undefined behavior, not because it will never happen, but specifically because it’s undefined.
- SAI_Peregrinus 5y agoAnd they're allowed to do whatever they want even with optimizations off.
- oconnor663 5y agoAnd future versions of your compiler are going to want to do different things with your UB than what your current compiler does.
- tialaramex 5y ago> In reality if you compile without optimization and with flags that avoid this stupid decisions it's not a problem. Worse programs. Written by people who believe "C is not a difficult language" and who sacrificed all benefits of using a high performance language because they couldn't understand what they were doing. So long as you don't have any competitors who use a better language or skilled programmers you can coast along like this, putting out a sub-par product and just pretending it's the best possible. But you can get a very sudden and rude awakening if anybody decide to offer what's possible here.
- pjmlp 5y agoEasy one uses an external Assembler like in the good old days when inline Assembly wasn't a feature one could rely on.