Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Feb 2002 15:36:40 -0800
From:      Peter Wemm <peter@wemm.org>
To:        Peter Dufault <dufault@hda.hda.com>
Cc:        "M. Warner Losh" <imp@village.org>, mike_makonnen@yahoo.com, current@FreeBSD.ORG
Subject:   Re: HEADS UP: cvs commit: src/sys/conf kern.pre.mk (fwd) 
Message-ID:  <20020226233640.BEDA93BB0@overcee.wemm.org>
In-Reply-To: <20020226094134.A503@hda.hda.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
Peter Dufault wrote:
> On Mon, Feb 25, 2002 at 11:35:12PM -0700, M. Warner Losh wrote:
> > In message: <1014700670.677.9.camel@blackbox.pacbell.net>
> >             Mike Makonnen <mike_makonnen@yahoo.com> writes:
> > : On Mon, 2002-02-25 at 20:59, M. Warner Losh wrote:
> > : > I've fixed a few of the low hanging fruit, but I don't know how to get
> > : > rid of warnings like:
> > : > 
> > : > const char *foo = "blah";
> > : > char *baz = foo;
> > : > 
> > : > when I know they are safe.
> > : 
> > : Correct me if I'm wrong, but isn't the correct declaration:
> > : 
> > : const char foo[] = "blah";
> > : char baz[] = "foo";
> > 
> > You miss the point.  First, there's no "" around foo.  Second, what I
> > quoted was boiled down from a bunch of macros and such.  Third, the
> > real example would be
> > 
> > volatile int conspeed;
> > int *foo = &conspeed;
> > 
> > Where foo is only accessed before all other accesses to conspeed.
> 
> When it is too twisty to fix at the moment I use macros such as:
> 
> #define BOGUSLY_CAST_AWAY_VOLATILITY(T,P) ((T)(unsigned int)(P))
> 
> ...
> 
> volatile int conspeed; int *foo =
> 	BOGUSLY_CAST_AWAY_VOLATILITY(int *, &conspeed);
> 
> to surpress the warnings.  You can easily redefine the macro to get
> them back so together with the discouraging name you're not sweeping
> things under the rug.

In sys/cdefs.h, we have:

#define     __DECONST(type, var)    ((type)(uintptr_t)(const void *)(var))

.. but bde threatened bodily harm for using it if I recall correctly.

There is also __DEVOLATILE() and __DEQUALIFY()

Cheers,
-Peter
--
Peter Wemm - peter@FreeBSD.org; peter@yahoo-inc.com; peter@netplex.com.au
"All of this is for nothing if we don't go to the stars" - JMS/B5


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020226233640.BEDA93BB0>