lib:util: Move discard_const(_p) to own header for libndr.h
[metze/samba/wip.git] / lib / util / discard.h
1 /*
2    Unix SMB/CIFS implementation.
3    Samba utility functions
4    Copyright (C) Andrew Tridgell 1992-1999
5    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _SAMBA_DISCARD_H_
22 #define _SAMBA_DISCARD_H_
23
24 /**
25   this is a warning hack. The idea is to use this everywhere that we
26   get the "discarding const" warning from gcc. That doesn't actually
27   fix the problem of course, but it means that when we do get to
28   cleaning them up we can do it by searching the code for
29   discard_const.
30
31   It also means that other error types aren't as swamped by the noise
32   of hundreds of const warnings, so we are more likely to notice when
33   we get new errors.
34
35   Please only add more uses of this macro when you find it
36   _really_ hard to fix const warnings. Our aim is to eventually use
37   this function in only a very few places.
38
39   Also, please call this via the discard_const_p() macro interface, as that
40   makes the return type safe.
41 */
42 #ifndef discard_const
43 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
44 #endif
45
46 /** Type-safe version of discard_const */
47 #ifndef discard_const_p
48 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
49 #endif
50
51 #endif /* _SAMBA_DISCARD_H_ */