L
Laurent Deniau
I am looking for the "cleanest" way to cast away the constness of a
pointee in C89, something like const_cast<T*>() in C++. Actually, I am
using:
#define CONST_CAST(typename,value) \
(((union { const typename cv; typename v; }*)&(value))->v)
which requires value to be an lvalue, but avoid compiler warning (gcc)
comparing to the brute force of ((typename)(value)):
extern const struct A *a_global;
struct A *a_local = CONST_CAST(struct A*,a_global); // no warning
(this macro is exclusively used to convert pointers to structures
which are known to be never defined const to a non-const ADT which is
never defined and forbid access to the components.)
The web seems to be rather silent on this topic so any hint/comment
are welcome.
a+, ld.
pointee in C89, something like const_cast<T*>() in C++. Actually, I am
using:
#define CONST_CAST(typename,value) \
(((union { const typename cv; typename v; }*)&(value))->v)
which requires value to be an lvalue, but avoid compiler warning (gcc)
comparing to the brute force of ((typename)(value)):
extern const struct A *a_global;
struct A *a_local = CONST_CAST(struct A*,a_global); // no warning
(this macro is exclusively used to convert pointers to structures
which are known to be never defined const to a non-const ADT which is
never defined and forbid access to the components.)
The web seems to be rather silent on this topic so any hint/comment
are welcome.
a+, ld.