Комментарии:
Was this ever implemented in the standard?
ОтветитьSo this is only for GNU compiler?
ОтветитьFrom the results I would say that gnu::const is something more than "does not modify global variables". It must be also "does not depend on global variables that could be modified from another thread or on volatile global variables (those could be modified from interrupt routines)". Otherwise both clang's and gcc's optimizers would render your code invalid
ОтветитьThat's the first thing you've covered that I used before. Nice. Finally beginning to tame the c++ beast.
Then again I am here because I took a pause because I just derped up a copy constructor. Oh well.
Thank you
ОтветитьI think it would have been better if you showed what happens when you label a function as pure but do use global state. Does compiler issues a warning or an error as I would hope. Or does it optimise the call site incorrectly opening a whole lot of ways things can break and will be nearly impossible to debug.
Do we even need pure attribute if function body is available in another translation unit for compiler to deduce that it is indeed pure. can't lto take care of it?
Fortran support pure functions since Fortran 95 in the language. (Pure is a keyword in Fortran)
ОтветитьThe constructor desctructor in C are meant to be used for shared objects.. the constructor function will load as it it were a main function in the SO file and the desctructor function will be called just before unloading the SO file or upon exiting the whole application :) I use them both and I like them both
ОтветитьWhy is "clang" optimizing using attributes in the "gnu" namespace? Is that allowed by the standard?
ОтветитьIf a const member function implies that the function does not change the state of the object, then I think it only makes sense that a const regular function would imply that it does not change the global state. This syntax would then make sense: void someRegularFunction(int x) const { /* */ }
I'm excited for attributes but this seems more like a qualifier than a decoration/attribute.
I feel like this is a big flaw of c++ because a previous compilation could already derive all these properties. We shouldn't have to annotate all these functions with particular properties if all the relevant information were still available in a binary format.
ОтветитьDose this work in c?
Ответить