www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Contracts in library code

reply bearophile <bearophileHUGS lycos.com> writes:
To solve the problem with Contracts in library code (like in Phobos or in
user-created libraries) is it possible to let DMD (asking it with a compiler
switch, I presume) compile and put inside the library two versions of each
function/method, with differently mangled names?

So when you import and use compiled functions from Phobos the linker uses the
version of the function with or without Contract assertions according to the
compilation switches (like -release) you have used.
Having a twice bigger Phobos lib in the standard DMD distribution is not a
problem, and the linker doesn't include the wrong functions, so the final
executable sizes are unchanged.

Bye,
bearophile
Dec 28 2010
parent Sean Kelly <sean invisibleduck.org> writes:
bearophile Wrote:

 To solve the problem with Contracts in library code (like in Phobos or in
user-created libraries) is it possible to let DMD (asking it with a compiler
switch, I presume) compile and put inside the library two versions of each
function/method, with differently mangled names?
 
 So when you import and use compiled functions from Phobos the linker uses the
version of the function with or without Contract assertions according to the
compilation switches (like -release) you have used.
I'd be fine with simply shipping two libs. DMD already has -defaultlib and -debuglib, the flags really just need to be -defaultlib and -releaselib. Shipping a separate lib for debug app builds isn't really useful anyway. -release also has to be the worst flag name ever.
Dec 28 2010