Justus Winter, le Mon 12 May 2014 12:05:41 +0200, a écrit :
> +/* An opaque type. You must not access these values directly. */
> +typedef uint64_t refcounts_t;
> +
> +/* Instead, the functions manipulating refcounts_t values write the
> + results into this kind of objects. */
> +struct references {
> + uint32_t hard;
> + uint32_t weak;
> +};
> +
> +union _references {
> + struct references refs;
> + refcounts_t rc;
> +};
> +
> +/* Initialize REF with HARD and WEAK references. */
> +static inline void
> +refcounts_init (refcounts_t *ref, uint32_t hard, uint32_t weak)
> +{
> + ((union _references *) ref)->refs =
AIUI this cast is a case of type-puning. Why not making refcounts_t the
union itself? That way would be clearly safe with gcc's extension.
Samuel