3 ms·
The D programming language has a 'pure' annotation which can be applied to functions. This enables the compiler checking that the function does not read or writ
by WalterBright 9y ago
The D programming language has a 'pure' annotation which can be applied to functions. This enables the compiler checking that the function does not read or write any global mutable state, including checking the functions called.
After using it for a while, it's amazing how much global variables tend to creep unannounced into code :-)
- tomjakubowski 9y ago> The D programming language has a 'pure' annotation which can be applied to functions. This enables the compiler checking that the function does not read or write any global mutable state, including checking the functions called. Are foreign calls assumed to be non-pure? Can they be marked pure in the case that the foreign (likely C) function doesn't reference global mutable state?
- WalterBright 9y ago> Are foreign calls assumed to be non-pure? Yes. > Can they be marked pure in the case that the foreign (likely C) function doesn't reference global mutable state? Yes. Here's an example: https://github.com/dlang/druntime/blob/master/src/core/stdc/stdlib.d#L187 https://github.com/dlang/druntime/blob/master/src/core/stdc/... It's true that the C Standard does not actually guarantee that they don't access mutable global state, but in practice they don't. We're not aware of one that does, and don't know why anyone would write one that does.
- syngrog66 9y agogreat feature, sir. thank you!
- WalterBright 9y agoYou're welcome! It's a 'little' feature with a surprisingly large impact.