Earlier quoted context omitted.
The C language until very recently didn't know about threads or other kinds of concurrency. So the compiler was technically free to assume that the interrupt is never called. It's nowhere in the call tree that originates at main(). Of course, it didn't do that. Because vendors imparted their compilers with additional knowledge about common programming patterns and uses that aren't standard C .
So there are vendors out there that alter the behavior of volatile to act like a mutex in multi-threaded environments but don't tell anyone? Ugh. Well, TI doesn't do that thankfully. At least not for the MSP430.
“C is how the computer works” is a dangerous mindset for C programmers
111–120 of 387 posts
Re: “C is how the computer works” is a dangerous mindset for C programmers
#112Edit: Oh I get it--your manager, who doesn't believe in leaky abstraction or UB, will beat you if the program fails.
Re: “C is how the computer works” is a dangerous mindset for C programmers
#113Actually I look forward for enough momentum to be created in the community, to allow new C standards to change the way undefined behaviors are conceived, and make them as specified as possible, and even when they cannot in reasonable unique ways, to provide reference possible behaviors to select in order to have the least unexpected outcome for the programmer. Especially now that low level programming is abstracting…
It would also be nice if Rust had a specification. Without a spec it's impossible to build a correct alternative Rust implementation.
Re: “C is how the computer works” is a dangerous mindset for C programmers
#114Someone told me back in high school that "C is just shorthand for assembly", which I think about a lot. Does anyone else feel that way?
> " Someone told me back in high school that 'C is just shorthand for assembly' " That was true for the PDP-11 that the article series mentions and it was true for the early home computers of the '70s and '80s but it became increasingly less true as processors became more and more complicated under the hood. That's kind of the point of the article series but it's not as big a deal as the author makes it out to be bec…
Re: “C is how the computer works” is a dangerous mindset for C programmers
#115Re: “C is how the computer works” is a dangerous mindset for C programmers
#116To be fair, even assembly language isn't how the computer works (gets translated into micro code). Not to mention other integral components like the GPU that are coded in an entirely different model. I think what's fair to say is: the "abstract C machine" tends to have a minimal amount of concepts on top of the machines instruction set, compared to other languages, and generally provides the least friction if you nee…
Not really, assembly language is extremely close to microcode, much much closer than it is to C. C has a whole bunch of baggage like pointer provenance, inability to read uninitialized memory, doesn't understand cache aliasing, etc that don't fit hardware well.
Re: “C is how the computer works” is a dangerous mindset for C programmers
#117Earlier quoted context omitted.
Not really, assembly language is extremely close to microcode, much much closer than it is to C. C has a whole bunch of baggage like pointer provenance, inability to read uninitialized memory, doesn't understand cache aliasing, etc that don't fit hardware well.
>inability to read uninitialized memory printf("%x", *(int*)0x12345678);
Re: “C is how the computer works” is a dangerous mindset for C programmers
#118Earlier quoted context omitted.
The C language until very recently didn't know about threads or other kinds of concurrency. So the compiler was technically free to assume that the interrupt is never called. It's nowhere in the call tree that originates at main(). Of course, it didn't do that. Because vendors imparted their compilers with additional knowledge about common programming patterns and uses that aren't standard C .
So there are vendors out there that alter the behavior of volatile to act like a mutex in multi-threaded environments but don't tell anyone? Ugh. Well, TI doesn't do that thankfully. At least not for the MSP430.
Re: “C is how the computer works” is a dangerous mindset for C programmers
#119Earlier quoted context omitted.
Not really, assembly language is extremely close to microcode, much much closer than it is to C. C has a whole bunch of baggage like pointer provenance, inability to read uninitialized memory, doesn't understand cache aliasing, etc that don't fit hardware well.
>inability to read uninitialized memory printf("%x", *(int*)0x12345678);
Re: “C is how the computer works” is a dangerous mindset for C programmers
#120C is like water. Atomically it is the DNA of all other programming languages. There's a reason why C is generally the fastest language with smaller binaries, and there's a reason why language like Python fallback to C for doing anything processor intensive. C will still be here when the latest fad languages of today are long forgotten.