Created
May 19, 2017 03:41
-
-
Save rustyrussell/4c32413c6daefc7b3cb1e25aab830c45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define STRUCTEQ_SAFE(t, ...) \ | |
static inline bool structeq_##t(const struct t *a, const struct t *b) \ | |
{ \ | |
return CPPMAGIC_JOIN(&&, STRUCTEQ_MAP2(STRUCTEQ_MEMBEREQ_, t, __VA_ARGS__)); \ | |
} | |
#define STRUCTEQ_MEMBEREQ_(t, m) \ | |
(memcmp(&a->m, &b->m, sizeof(a->m)) == 0) | |
/* Stolen from cppmagic, but with a extra arg added. */ | |
#define _STRUCTEQ_MAP2_() _STRUCTEQ_MAP2 | |
#define _STRUCTEQ_MAP2(m_, a1_, a_, ...) \ | |
m_(a1_, a_) \ | |
CPPMAGIC_IFELSE(CPPMAGIC_NONEMPTY(__VA_ARGS__)) \ | |
(, CPPMAGIC_DEFER2(_STRUCTEQ_MAP2_)()(m_, a1_, __VA_ARGS__)) \ | |
() | |
#define STRUCTEQ_MAP2(m_, a1_, ...) \ | |
CPPMAGIC_IFELSE(CPPMAGIC_NONEMPTY(__VA_ARGS__)) \ | |
(CPPMAGIC_EVAL(_STRUCTEQ_MAP2(m_, a1_, __VA_ARGS__))) \ | |
() | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stddef.h> | |
#include <string.h> | |
#include <ccan/structeq/structeq.h> | |
struct short_channel_id { | |
uint16_t outnum; | |
uint64_t blocknum; | |
uint32_t txnum; | |
}; | |
STRUCTEQ_MAP2(STRUCTEQ_MEMBEREQ_, t, a, b) | |
//CPPMAGIC_JOIN(&&, 1, STRUCTEQ_MAP2(STRUCTEQ_MEMBEREQ_, t, a, b)) | |
//STRUCTEQ_SAFE(short_channel_id, outnum, blocknum, txnum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment