Don't just let your compiler boss you around, you're better than that.
*suddenly switches to a more sinister tone*
Just write naked functions for a while and let it see how much you don't need it.
Don't just let your compiler boss you around, you're better than that.
*suddenly switches to a more sinister tone*
Just write naked functions for a while and let it see how much you don't need it.
@mage_of_dragons actually this could be useful for me.
later of course.
@loganer it tends to do that yeah x3
There's usually a volatile or some constraint you can do though
@mage_of_dragons I really don't want to jump through all these whoops to get the compiler to just compile what I wrote, it's kind of really silly how this came about.
you'd think these optimizations would be opt-in but nope ... because supposedly the compiler people know better (they really don't but they like to think they do.)
most of the basic optimizations are opt-out actually.
to do debugging for instance you have to pass in -O0 to the commandline but even that doesn't turn off all the optimization stuff.
the existence of volatile as a keyword demonstrates this as well, this keyword would not need to exist if the optimizations were opt-in.
@loganer Well yeah, if the compiler were to make something like struct alignment opt-in, it'd do a lot more harm than good.
> the existence of volatile as a keyword demonstrates this as well, this keyword would not need to exist if the optimizations were opt-in.
I don't see how its existence makes optimizations opt-in. It's there that *if* some optimization that would cause it to break were enabled, the compiler doesn't apply it.
@mage_of_dragons it's existence proves that it's opt-out and it would not need to exist if the optimization was opt-in as the optimization would be selected on the commmandline during compile time.
I just want the compiler to take the input code and do absolutely nothing to it and translate it directly into assemble... is that too hard?
@loganer Say I have
```c
#include <stdio.h>
void test() {
int test = 32;
printf("%d", test);
}
```
The memory write will get executed with no opts, but will be optimized to use a register with as low as -O1.
If I make it volatile, the memory write is preserved even with -O3. This is what volatile is for, to mark the places that have side effects the compiler might not understand, *should* the program ever be compiled with optimizations. Without opts, volatile may as well be ignored.
let me demonstrate the real problem here...
```c
void test() {
int test = 0;
if(test){
printf("%d", test);
}
}
```
it is part of the problem, yes, and the most easily demonstrable part...
but it is not the whole problem, which is a bit more broader.
if I wanted to keep this "dead code" for whatever reason, I would need to explicitly opt-out of the optimization via usage of volatile.
but on a much large or more complex system this could easily be forgotten ... unless I choose to make litterally everything volatile.
@mage_of_dragons then let it do that and throw a warning if you absolutely must do anything.
at least if you don't tamper with the code then I know it's 100% my fault and then I can handle that.