2 * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * \ingroup Implementation
23 #ifndef GLOBAL_NODESTRUCT_HPP
24 #define GLOBAL_NODESTRUCT_HPP
26 /** Declare a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */
27 #define DCL_NODESTRUCT_GLOBAL(TYPE,NAME)\
28 namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) extern uint8_t NAME[sizeof(TYPE)]; }\
29 /* awkwardly written to silence gcc's -Wstrict-aliasing because _Pragma("GCC diagnostic ignored \"-Wstrict-aliasing\"") is bugged */\
30 static inline TYPE &NAME() { auto p = static_cast<void*>(&detail_NODESTRUCT_GLOBAL::NAME[0]); return *reinterpret_cast<TYPE*>(p); }\
31 namespace detailInit_NODESTRUCT_GLOBAL { __attribute__((constructor(101))) static void NAME() { new(&::NAME()) TYPE(); } }
33 /** Define a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */
34 #define DEF_NODESTRUCT_GLOBAL(TYPE,NAME)\
35 namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) uint8_t NAME[sizeof(TYPE)]; }
38 #endif // GLOBAL_NODESTRUCT_HPP