[zeromq-dev] type safe sockets

john skaller skaller at users.sourceforge.net
Sun Feb 12 00:49:25 CET 2012

On 12/02/2012, at 9:04 AM, john skaller wrote:

Ok, this is done. To use the patch (when it's pulled) convert your code to use


instead of void*. in 3.x, these are defined to void * anyhow.

To check you code, do this:

#include <zmq.h>

The compiler will barf where you're still using a void*. Fix it.
When you get bored, just remove the #define.

If you want to you can also 


and that forces the type safe interface, and


forces the unsafe interface. So in 4.0 you can still use the old
interface, and in 3.1 you can try out the new one.

The implementation technique cheats. It assumes a struct
containing a void * will be passed the same way as a void*.
If your compiler does not do this, all hell will break loose.
This only matters if you're using the type safe interface.

The cheat is there so you don't need two versions of the zmq 
library binary to commence any upgrades. if you use the emulation
technique, it doesn't matter. The idea is that you can check the
safety of your program, and even if the linked program crashes,
you can just remove the switch and recompile your app:
the type safety checks have been done, removing the switch
doesn't undo any fixes you made to your program.

john skaller
skaller at users.sourceforge.net

More information about the zeromq-dev mailing list