]>
git.proxmox.com Git - mirror_frr.git/blob - lib/compiler.h
2 * Copyright (c) 2015-2017 David Lamparter, for NetDEF, Inc.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef _FRR_COMPILER_H
18 #define _FRR_COMPILER_H
20 /* function attributes, use like
21 * void prototype(void) __attribute__((_CONSTRUCTOR(100)));
23 #if defined(__clang__)
24 #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 5)
25 # define _RET_NONNULL , returns_nonnull
27 # define _CONSTRUCTOR(x) constructor(x)
28 #elif defined(__GNUC__)
29 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
30 # define _RET_NONNULL , returns_nonnull
32 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
33 # define _CONSTRUCTOR(x) constructor(x)
34 # define _DESTRUCTOR(x) destructor(x)
35 # define _ALLOC_SIZE(x) alloc_size(x)
40 /* Solaris doesn't do constructor priorities due to linker restrictions */
45 /* fallback versions */
50 # define _CONSTRUCTOR(x) constructor
53 # define _DESTRUCTOR(x) destructor
56 # define _ALLOC_SIZE(x)
60 * for warnings on macros, put in the macro content like this:
61 * #define MACRO BLA CPP_WARN("MACRO has been deprecated")
66 #define CPP_NOTICE(text) _Pragma(CPP_STR(message __FILE__ ": " text))
67 #define CPP_WARN(text) CPP_NOTICE(text)
69 #elif (defined(__GNUC__) \
70 && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) \
71 || (defined(__clang__) \
72 && (__clang_major__ >= 4 \
73 || (__clang_major__ == 3 && __clang_minor__ >= 5)))
74 #define CPP_WARN(text) _Pragma(CPP_STR(GCC warning text))
75 #define CPP_NOTICE(text) _Pragma(CPP_STR(message text))
78 #define CPP_WARN(text)
79 #define CPP_NOTICE(text)
82 #endif /* _FRR_COMPILER_H */