]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compat: define a new empty type empty_t for non-implemented fields
authorWilly Tarreau <w@1wt.eu>
Tue, 21 May 2019 17:48:44 +0000 (19:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 21 May 2019 18:03:03 +0000 (20:03 +0200)
Some structures have optional fields which depend on availability of
certain features on certain platforms, and having to stuff lots of
ifdefs in these structs makes them unreadable. Using real values like
ints requires some initialization and adds even more confusion.

Here we take a different approach : we create an empty type called
empty_t to use as a substitute for the real type that is not implemented
and which doesn't contain any value (it's an empty struct). Thus it has
a size of zero but an address, thus a pointer may point to it. It will
not have to be initialized though. Some initialization code might even
continue to work and do nothing like initializing it using memset with
its sizeof which is zero.

include/common/compat.h

index 35782dee2b06228b5aa3e793662a43c55bb06036..07b3666e33ebd29b9fb199f453c37c7971783405 100644 (file)
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 
+/* set any optional field in a struct to this type to save ifdefs. Its address
+ * will still be valid but it will not reserve any room nor require any
+ * initialization.
+ */
+typedef struct { } empty_t;
+
 // Redefine some limits that are not present everywhere
 #ifndef LLONG_MAX
 # define LLONG_MAX 9223372036854775807LL