tech-x11 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

client side hackers note.



After struggling for some time trying to get a 20 year old
program to build under (7_BETA) bsd.x11.mk, an unrelated
browse through <sys/cdefs.h> revealed this handy item:

/*
 * The following macro is used to remove const cast-away warnings
 * from gcc -Wcast-qual; it should be used with caution because it
 * can hide valid errors; in particular most valid uses are in
 * situations where the API requires it, not to cast away string
 * constants. We don't use *intptr_t on purpose here and we are
 * explicit about unsigned long so that we don't have additional
 * dependencies.
 */
#define __UNCONST(a)    ((void *)(unsigned long)(const void *)(a))

Quite useful when passing input to vaguely declared Xlib routines
expecting, say, a char* while using -Wwrite-strings and -Wcast-qual.

A further advantage to judicious use of this is, that it will serve
to identify Xlib routines that might be more carefully declared, for
the upstream channel.

It is perceivable that this is well known to some or many on this
list, but for those, like me, who were unaware of it, a handy, if
sub-optimal, fix.

Like it says, use with caution.

/pjr\



Home | Main Index | Thread Index | Old Index