Andy Dougherty wrote:

On Wed, 30 Oct 2002, Leopold Toetsch wrote:

[sundry 'const' warnings]

Nicholas Clark suggested that we could perhaps use a union, something like

Nice idea - works for me (gcc 2.95.2)

Slightly modified - please try this (cc -Wall -Wcast-qual ..)

static union {
	const void * __c_ptr;
	void * __ptr;
} __ptr_u;

#define const_cast(b) (__ptr_u.__c_ptr = (b), __ptr_u.__ptr)

char *f(const void *b)
{
	char *s = (char*) const_cast(b);
	return s;
}
int main() {
	char *s = f("abc");
	return *s != 'a';
}

leo

Reply via email to