C++ Weekly - Ep 144 - Pure Functions in C++

C++ Weekly - Ep 144 - Pure Functions in C++

C++ Weekly With Jason Turner

5 лет назад

14,543 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Versachiful
@Versachiful - 04.03.2023 09:17

Was this ever implemented in the standard?

Ответить
@openroomxyz
@openroomxyz - 02.06.2022 14:47

So this is only for GNU compiler?

Ответить
@pazdziochowaty
@pazdziochowaty - 09.09.2019 03:40

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

Ответить
@TheR971
@TheR971 - 22.05.2019 03:20

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.

Ответить
@danielphd5072
@danielphd5072 - 05.12.2018 11:54

Thank you

Ответить
@abbyssoul
@abbyssoul - 04.12.2018 02:35

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?

Ответить
@svenjohannsen
@svenjohannsen - 04.12.2018 00:15

Fortran support pure functions since Fortran 95 in the language. (Pure is a keyword in Fortran)

Ответить
@voltenheim
@voltenheim - 04.12.2018 00:00

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

Ответить
@drdanz79
@drdanz79 - 03.12.2018 22:45

Why is "clang" optimizing using attributes in the "gnu" namespace? Is that allowed by the standard?

Ответить
@bdafeesh
@bdafeesh - 03.12.2018 20:50

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.

Ответить
@DreyriRS
@DreyriRS - 03.12.2018 20:07

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.

Ответить
@oj0024
@oj0024 - 03.12.2018 19:43

Dose this work in c?

Ответить