[zeromq-dev] How to write libraries

Dimiter 'malkia' Stanev malkia at gmail.com
Tue Nov 8 04:09:30 CET 2011


	That's a very good advice, except (personally though) maybe for autotools.

	One point about #define vs. enum - I used to like former, but now I 
like the latter, there is a middle ground:

	enum {
		KEY_UP = 100
	};
	#define KEY_UP KEY_UP

	This way, preprocessed .c/.cpp keeps the value, and can be reused 
quickly for environments which can parse "C" syntax, to the point that 
they can import any "C" declaration. (luajit ffi for example) 
http://luajit.org/ext_ffi_tutorial.html

	The latter one (#define) then is useful for other such systems that 
automatically import values, or maybe they have only preprocessor, 
rather than full blown "C" parser.

	In any case, it was real easy job wrapping libzmq for luajit ffi (note: 
there is more mature lua binding for libzmq already in another lib, 
which is mentioned in the zeromq site):

	https://github.com/malkia/ufo/blob/master/ffi/zmq.lua

	A note: There is something fishy about WINDOWS ERROR CODES in the ZMQ 
library.

	I don't think checking for #ifndef E_SOMETHING, then #define 
E_SOMETHING (ZMQ_HAUSNUMERO + MagicValue) is safe.

	Certain E_xxx errors are defined in one Windows SDK, and not in WDKs

	A better approach is to always declare them

	Even better would be if errors are the same across all platforms (less 
work for binding writers).

On 11/3/2011 7:09 AM, Martin Sustrik wrote:
> Nice summary:
>
> https://git.kernel.org/?p=linux/kernel/git/kay/libabc.git;a=blob_plain;f=README
>
> Martin



More information about the zeromq-dev mailing list