code_junkie

interfacing with stdbool.h C++

Nov 10th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #ifndef _STDBOOL_H
  2. #define _STDBOOL_H
  3.  
  4. /* C99 Boolean types for compilers without C99 support */
  5. /* http://www.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html */
  6. #if !defined(__cplusplus)
  7.  
  8. #if !defined(__GNUC__)
  9. /* _Bool builtin type is included in GCC */
  10. typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
  11. #endif
  12.  
  13. #define bool _Bool
  14. #define true 1
  15. #define false 0
  16. #define __bool_true_false_are_defined 1
  17.  
  18. #endif
  19.  
  20. #endif
  21.  
  22. //#define bool _Bool
  23. #define bool unsigned char
  24.  
  25. #ifndef _STDBOOL_H
  26. #define _STDBOOL_H
  27.  
  28. #include
  29.  
  30. /* C99 Boolean types for compilers without C99 support */
  31. /* http://www.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html */
  32. #if !defined(__cplusplus)
  33.  
  34. #if !defined(__GNUC__)
  35. /* _Bool builtin type is included in GCC */
  36. /* ISO C Standard: 5.2.5 An object declared as
  37. type _Bool is large enough to store
  38. the values 0 and 1. */
  39. /* We choose 8 bit to match C++ */
  40. /* It must also promote to integer */
  41. typedef int8_t _Bool;
  42. #endif
  43.  
  44. /* ISO C Standard: 7.16 Boolean type */
  45. #define bool _Bool
  46. #define true 1
  47. #define false 0
  48. #define __bool_true_false_are_defined 1
  49.  
  50. #endif
  51.  
  52. #endif
  53.  
  54. union boolean {
  55. bool value_cpp;
  56. int value_c;
  57. };
  58.  
  59. extern "C" bool library_func_1(int i, char c, bool b);
  60.  
  61. bool library_func_1_cpp(int i, char c, bool b)
  62. {
  63. int result = library_func_1(i, c, static_cast<int>(b));
  64. return (result==true);
  65. }
Add Comment
Please, Sign In to add comment