What is pure used for?

sclytrack fake at hotmail.com
Thu Nov 25 07:26:48 UTC 2021


My understanding is that pure is used for compiler optimization 
in loops and expressions. It leaves out multiple calls if it 
figures out it is not needed.

Is pure used for anything else?


int * pureFunction()

1) the pointer needs to be the same.
2) the value that the pointer points to needs to be the same. I 
call this the "value
of interest" with relation to pure. The pointer doesn't matter.
3) both the pointer and the value the pointer is pointing too 
needs to be the same.

pureCalloc() satisfies (2)
pureMalloc() violates everything.

Does the D compiler do any optimizations?



More information about the Digitalmars-d-learn mailing list