xref: /netbsd-src/share/man/man3/__UNCONST.3 (revision d19876761f82df32a97e59addba9b6aa5a56c139)
1.\"	$NetBSD: __UNCONST.3,v 1.7 2013/10/17 20:43:49 wiz Exp $
2.\"
3.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jukka Ruohonen.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd October 17, 2013
31.Dt __UNCONST 3
32.Os
33.Sh NAME
34.Nm __UNCONST
35.Nd compile time cast-away macro
36.Sh SYNOPSIS
37.In sys/cdefs.h
38.Ft void
39.Fn __UNCONST x
40.Ft void
41.Fn __UNVOLATILE x
42.Sh DESCRIPTION
43The
44.Fn __UNCONST
45macro can be used to omit warnings produced by certain compilers when
46operating with pointers declared with the
47.Em const
48type qualifier in a context without such qualifier.
49Examples include passing a pointer declared with the
50.Em const
51qualifier to a function without such qualifier,
52and variable assignment from a
53.Em const
54pointer to a non-const pointer.
55In the same vein, the
56.Fn __UNVOLATILE
57macro can be used to exclude warnings related to the
58.Em volatile
59type qualifier.
60.Sh IMPLEMENTATION NOTES
61These macros are implemented by explicitly using
62.Em unsigned long
63instead of
64.Em intptr_t ,
65a signed type guaranteed to hold a pointer.
66.Sh SEE ALSO
67.Xr cc 1 ,
68.Xr cdefs 3
69.Sh CAVEATS
70As both macros may hide valid errors, their usage is not recommended
71unless there is a well-thought reason for a cast.
72A typical use case for
73.Fn __UNCONST
74involve an
75.Tn API
76that does not follow the so-called ``const correctness''
77even if it would be appropriate.
78Valid use cases of
79.Fn __UNVOLATILE
80include passing a
81.Em volatile
82pointer to
83.Xr memset 3 .
84.Pp
85Use of this macro is non-portable; this is part of the implementation
86namespace and should only be used in
87.Nx
88code.
89