From 39b46a02b7199786e926dfcb4086544789e30a68 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 21 Oct 2019 15:09:20 +0000 Subject: [PATCH] bitmap: Allow bitmap type to be forward declared MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Currently bitmap type is defined via untagged struct which makes it impossible to forward declare it. Forward-declaring is useful since all bitmap functions only use bitmap* and in public user-visible headers/datastructures it is enough to indicate that a data field with bitmap pointer is there, whereas bitmap.h can be included only in implementation. Beside that some headers are included by both C and C++ parts of a project, and when ccan/bitmap.h is processed by C++ compiler it gives: ./3rdparty/ccan/ccan/bitmap/bitmap.h: In function ‘bitmap* bitmap_alloc(long unsigned int)’: ./3rdparty/ccan/ccan/bitmap/bitmap.h:201:15: error: invalid conversion from ‘void*’ to ‘bitmap*’ [-fpermissive] return malloc(bitmap_sizeof(nbits)); ~~~~~~^~~~~~~~~~~~~~~~~~~~~~ ./3rdparty/ccan/ccan/bitmap/bitmap.h: In function ‘bitmap* bitmap_realloc0(bitmap*, long unsigned int, long unsigned int)’: ./3rdparty/ccan/ccan/bitmap/bitmap.h:227:18: error: invalid conversion from ‘void*’ to ‘bitmap*’ [-fpermissive] bitmap = realloc(bitmap, bitmap_sizeof(nbits)); ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./3rdparty/ccan/ccan/bitmap/bitmap.h: In function ‘bitmap* bitmap_realloc1(bitmap*, long unsigned int, long unsigned int)’: ./3rdparty/ccan/ccan/bitmap/bitmap.h:238:18: error: invalid conversion from ‘void*’ to ‘bitmap*’ [-fpermissive] bitmap = realloc(bitmap, bitmap_sizeof(nbits)); -> Give to users ability not to force-include ccan/bitmap.h by forward-declaring bitmaps like this: typedef struct bitmap bitmap; ... struct MyStruct { bitmap *my_bitmap; }; Cc: David Gibson Signed-off-by: Kirill Smelkov Message-Id: <20191021150903.25159-1-kirr@nexedi.com> Signed-off-by: David Gibson --- ccan/bitmap/bitmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ccan/bitmap/bitmap.h b/ccan/bitmap/bitmap.h index beeb1e95..54382801 100644 --- a/ccan/bitmap/bitmap.h +++ b/ccan/bitmap/bitmap.h @@ -21,7 +21,7 @@ typedef unsigned long bitmap_word; /* * We wrap each word in a structure for type checking. */ -typedef struct { +typedef struct bitmap { bitmap_word w; } bitmap; -- 2.39.2