[D1] struct opEquals questions

bearophile bearophileHUGS at lycos.com
Thu Mar 18 08:09:28 PDT 2010


qwerty:
> If I return *this, I should also provide the *S version of opEquals? 

If you don't provide a necessary operator the compiler complaints.


> What happens with the return value if it isn't used?

The function is one and it doesn't change, it has to be the same for everyone that calls it (time ago I have suggested for a compile time flag that's defined inside functions to know if their result is used, to avoid computing it in some situations, turning the single function in a kind of templated function, but I am not sure it can work well if you have function pointers. So you need a single entry point for two functions).


> I mean, where will the *this end up? Or will the compiler not return it at all?

The function returns it, but the result is ignored. In such situations reading a little the asm helps.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list