MRPT  1.9.9
initializer.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 /** \file Usage: MRPT_INITIALIZER(func) { ... }
13  * MRPT_INITIALIZER() should be used only once per library in its present
14  * cross-platform implementation.
15  */
16 #if defined(_MSC_VER)
17 #include <mrpt/config.h>
18 #if defined(MRPT_BUILT_AS_DLL)
19 #include <windows.h>
20 #define MRPT_INITIALIZER(f) \
21  static void f(); \
22  BOOL WINAPI DllMain( \
23  HINSTANCE /*hinstDLL*/, DWORD fdwReason, LPVOID /*lpvReserved*/) \
24  { \
25  switch (fdwReason) \
26  { \
27  case DLL_PROCESS_ATTACH: \
28  f(); \
29  } \
30  return TRUE; \
31  } \
32  static void f(void)
33 #else
34 // Static libs in Windows: the hardest case, subject to be optimized out
35 #define MRPT_INITIALIZER(f) \
36  static void f(void); \
37  struct f##_t_ \
38  { \
39  f##_t_(void) { f(); } \
40  }; \
41  static f##_t_ f##_; \
42  static void f(void)
43 #endif
44 #else
45 #define MRPT_INITIALIZER(f) \
46  static void f(void) __attribute__((constructor)) __attribute__((used)); \
47  static void f(void)
48 #endif



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019