|
|
Subscribe / Log in / New account

Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)

Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)

Posted Nov 7, 2023 10:24 UTC (Tue) by mb (subscriber, #50428)
In reply to: Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack) by vadim
Parent article: Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)

>Because by specifying the "optimize" flag

So we're back to: You must specify -O0, if you "program to the hardware".


to post comments

Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)

Posted Nov 7, 2023 19:12 UTC (Tue) by vadim (subscriber, #35271) [Link] (2 responses)

No, I don't think even that will do if you're counting cycles, because even with -O0 the possibility exists that the compiler will make different decisions about what instructions to use depending on bug fixes/implementation. I don't think there's for instance any guarantee that GCC and Clang will both produce the same binary with -O0 in anything but the most trivial cases.

So if you're counting cycles you should probably be actually coding it in assembler.

Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)

Posted Nov 7, 2023 19:17 UTC (Tue) by mb (subscriber, #50428) [Link] (1 responses)

So you are saying that you can't "program to the hardware" in C at all?
I fully agree.

Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)

Posted Nov 8, 2023 13:16 UTC (Wed) by vadim (subscriber, #35271) [Link]

You can to a limited extent.

Eg, under DOS you can write C code that sets interrupt handlers, or does low level control of the floppy drive. The ability to do such low level things is precisely why C gets used to write operating systems.

Like I said elsewhere, "portable assembler" is in my view a very metaphorical description, because obviously there can't be such a thing in the absolute sense. Proper assembler reflects the CPU's architecture, and a single language can't accurately depict the wildly different designs that exist. However it can get there part of the way given some compromises.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds