]> git.ozlabs.org Git - ccan/blobdiff - ccan/tcon/tcon.h
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / tcon / tcon.h
index 1dbadafc9726716e6d19d82794ab22b461ef4903..df3aac88b785a4acc241e125a9c377766a55272d 100644 (file)
  * It evaluates to @x so you can chain it.
  */
 #define tcon_check_ptr(x, canary, expr)                                \
-       (sizeof(&(x)->_tcon[0].canary == (expr)) ? (x) : (x))
-
+       (sizeof((expr) ? (expr) : &(x)->_tcon[0].canary) ? (x) : (x))
 
 /**
  * tcon_type - the type within a container (or void *)
  * tcon_container_of() evaluates to a pointer to the container
  * structure.  With sufficient compiler support, the pointer will be
  * correctly typed, and the type of @member_ptr will be verified.
+ * Note that const is discarded; a const @member_ptr still yields a
+ * non-const container (unless @canary is const).
  *
  * Returns NULL if @member_ptr is NULL.
  */
                canary, tcon_container_of_((member_ptr),                \
                                           tcon_offset((x), canary)))
 
-static inline void *tcon_container_of_(void *member_ptr, size_t offset)
+static inline void *tcon_container_of_(const void *member_ptr, size_t offset)
 {
        return member_ptr ? (char *)member_ptr - offset : NULL;
 }