Main MRPT website > C++ reference for MRPT 1.9.9
initializer.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://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
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 #include <stdio.h>
46 #include <stdlib.h>
47 #define MRPT_INITIALIZER(f) \
48  static void f(void) __attribute__((constructor)) __attribute__((used)); \
49  static void f(void)
50 #endif



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST