Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

.\"	$NetBSD: __UNCONST.3,v 1.7 2013/10/17 20:43:49 wiz Exp $
.\"
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jukka Ruohonen.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd October 17, 2013
.Dt __UNCONST 3
.Os
.Sh NAME
.Nm __UNCONST
.Nd compile time cast-away macro
.Sh SYNOPSIS
.In sys/cdefs.h
.Ft void
.Fn __UNCONST x
.Ft void
.Fn __UNVOLATILE x
.Sh DESCRIPTION
The
.Fn __UNCONST
macro can be used to omit warnings produced by certain compilers when
operating with pointers declared with the
.Em const
type qualifier in a context without such qualifier.
Examples include passing a pointer declared with the
.Em const
qualifier to a function without such qualifier,
and variable assignment from a
.Em const
pointer to a non-const pointer.
In the same vein, the
.Fn __UNVOLATILE
macro can be used to exclude warnings related to the
.Em volatile
type qualifier.
.Sh IMPLEMENTATION NOTES
These macros are implemented by explicitly using
.Em unsigned long
instead of
.Em intptr_t ,
a signed type guaranteed to hold a pointer.
.Sh SEE ALSO
.Xr cc 1 ,
.Xr cdefs 3
.Sh CAVEATS
As both macros may hide valid errors, their usage is not recommended
unless there is a well-thought reason for a cast.
A typical use case for
.Fn __UNCONST
involve an
.Tn API
that does not follow the so-called ``const correctness''
even if it would be appropriate.
Valid use cases of
.Fn __UNVOLATILE
include passing a
.Em volatile
pointer to
.Xr memset 3 .
.Pp
Use of this macro is non-portable; this is part of the implementation
namespace and should only be used in
.Nx
code.