Hi,
i am currently trying to fix the -Wcast-qual warnings. In include/wine/unicode.h there a 4 function:
static inline int strncmpW( const WCHAR *str1, const WCHAR *str2, int n) static inline WCHAR *strchrW( const WCHAR *str, WCHAR ch ) static inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch ) static inline WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept )
whose signatures forces us to discard the const of an parameter while returning it as the function value. Compiling with -Wcast-qual gives (correctly) this warning:
../../include/wine/unicode.h:218: warning: cast discards qualifiers from pointer target type
Together these four functions account for a total of 1400 (!) warnings.
In samba_4 sourcecode i discovered the following macros, which are apparently a hack but silences these warnings:
#define discard_const(ptr) ((void *)((intptr_t)(ptr))) #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
an crude proof of concept is attached as a patch.
I am not sure how portable this solution is...
Any comments are welcome...
Regards, Stefan
Stefan Huehner wrote:
I am not sure how portable this solution is...
To make it portable you can use ULONG_PTR instead of intptr_t.
Jacek
Hi,
On Mon, Jun 20, 2005 at 10:26:32PM +0200, Stefan Huehner wrote about 'unicode.h and -Wcast-qual':
Hi,
i am currently trying to fix the -Wcast-qual warnings. In include/wine/unicode.h there a 4 function:
In samba_4 sourcecode i discovered the following macros, which are apparently a hack but silences these warnings:
#define discard_const(ptr) ((void *)((intptr_t)(ptr))) #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
an crude proof of concept is attached as a patch.
I am not sure how portable this solution is...
It should be fairly portable as it works on all of the platforms Samba runs on, which includes odd ones such as AIX, Cray, various BSDs, solaris..
Cheers,
Jelmer
On Mon, Jun 20, 2005 at 10:26:32PM +0200, Stefan Huehner wrote:
In samba_4 sourcecode i discovered the following macros, which are apparently a hack but silences these warnings:
#define discard_const(ptr) ((void *)((intptr_t)(ptr))) #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
Or:
static inline void *deconst(const void *p) { return ((const char *)p - (const char *)0) + (char *)0; }
David