Added a INIT() macro to initialize class instances
authorMartin Willi <martin@strongswan.org>
Tue, 8 Dec 2009 15:11:37 +0000 (16:11 +0100)
committerMartin Willi <martin@strongswan.org>
Thu, 17 Dec 2009 12:53:24 +0000 (13:53 +0100)
src/libstrongswan/utils.h

index 3f8ffc6..ebc67db 100644 (file)
 #define POS printf("%s, line %d\n", __FILE__, __LINE__)
 
 /**
+ * Object allocation/initialization macro, using designated initializer.
+ */
+#define INIT(this, ...) { (this) = malloc(sizeof(*this)); \
+                                                 *(this) = (typeof(*this)){ __VA_ARGS__ }; }
+
+/**
  * Macro to allocate a sized type.
  */
 #define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))