On an internet forum I see a user talking about realloc and POSIX. He quotes the specification saying:

The realloc() function shall deallocate the old object pointed to by ptr and return a pointer to a new object that has the size specified by size.

The said user then points out that the specification uses the word 'shall' instead of 'must'. He elaborates that because of this the implementation of realloc might vary on different platforms and then suggests to avoid using realloc in order to not have memory leaks.

I'm not native to English, so I may be wrong, but my understanding of 'shall' differs from what was said above. To my (possibly flawed) understanding 'shall' describes an imperative; it lies somewhere between 'should' and 'will' - so it is such a strong imperative that it almost refuses to acknowledge that there may happen something contrary. Everyone knows these lines:

I am the Lord thy God. Thou shalt have no other gods before me. Thou shalt not make unto thee any graven image. Thou shalt not take the name of the Lord thy God in vain. Remember the sabbath day, to keep it holy. Honour thy father and thy mother. Thou shalt not kill. Thou shalt not commit adultery. Thou shalt not steal. Thou shalt not bear false witness against thy neighbour. Thou shalt not covet.

I understand these to be are absolute imperatives that do not allow disobedience; and in this same way I was interpreting the word 'shall' in POSIX specification and in any other similar text.

Was my understanding correct? Or was it not?

In particular - does the word 'shall' allow 'realloc' implementations to not deallocate the old object?

0 Answers