updates.
[silc.git] / lib / silcutil / silctypes.h
index fdb3e73d152aa3b79ea6bc9931182a2ab4abab2d..5577ae4208d62e1889a8f897e64a302fa78dee4e 100644 (file)
 #ifndef SILCTYPES_H
 #define SILCTYPES_H
 
+/****d* silcutil/SILCTypes/TRUE
+ *
+ * NAME
+ *
+ *    #define TRUE ...
+ *
+ * DESCRIPTION
+ *
+ *    Boolean true value indicator.
+ *
+ * SOURCE
+ */
 #ifndef TRUE
 #define TRUE 1
 #endif
+/***/
+
+/****d* silcutil/SILCTypes/FALSE
+ *
+ * NAME
+ *
+ *    #define FALSE ...
+ *
+ * DESCRIPTION
+ *
+ *    Boolean false value indicator.
+ *
+ * SOURCE
+ */
 #ifndef FALSE
 #define FALSE 0
 #endif
+/***/
 
-/* Define offsetof */
-#ifndef offsetof
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+/****d* silcutil/SILCTypes/bool
+ *
+ * NAME
+ *
+ *    #define bool ...
+ *
+ * DESCRIPTION
+ *
+ *    Boolean value, and is 8-bits.  Represents value 0 or 1.  In
+ *    C++ code this type is defined by the C++, and this definition is
+ *    not used.
+ *
+ * SOURCE
+ */
+#ifndef __cplusplus
+#ifndef bool
+#define bool unsigned char
 #endif
+#endif
+/***/
+
+#define silc_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 
 #if SILC_SIZEOF_SHORT > 2
 #error "size of the short must be 2 bytes"
@@ -198,11 +243,7 @@ typedef SilcInt32 SilcInt64;
 typedef SilcUInt32 * void *;
 #endif
 
-#ifndef __cplusplus
-#ifndef bool
-#define bool unsigned char
-#endif
-#endif
+/* Macros */
 
 #define GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24    \
                    | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16)    \
@@ -222,8 +263,10 @@ typedef SilcUInt32 * void *;
  * SOURCE
  */
 #define SILC_GET16_MSB(l, cp)                          \
+do {                                                   \
        (l) = ((SilcUInt32)(SilcUInt8)(cp)[0] << 8)     \
-           | ((SilcUInt32)(SilcUInt8)(cp)[1])
+           | ((SilcUInt32)(SilcUInt8)(cp)[1]);         \
+} while(0)
 /***/
 
 /****d* silcutil/SILCTypes/SILC_GET32_MSB
@@ -239,10 +282,12 @@ typedef SilcUInt32 * void *;
  * SOURCE
  */
 #define SILC_GET32_MSB(l, cp)                          \
+do {                                                   \
        (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24    \
            | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16)    \
            | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8)     \
-           | ((SilcUInt32)(SilcUInt8)(cp)[3])
+           | ((SilcUInt32)(SilcUInt8)(cp)[3]);         \
+} while(0)
 /***/
 
 /****d* silcutil/SILCTypes/SILC_GET64_MSB
@@ -258,8 +303,10 @@ typedef SilcUInt32 * void *;
  * SOURCE
  */
 #define SILC_GET64_MSB(l, cp)                          \
+do {                                                   \
        (l) = ((((SilcUInt64)GET_WORD((cp))) << 32) |   \
-             ((SilcUInt64)GET_WORD((cp) + 4)))
+             ((SilcUInt64)GET_WORD((cp) + 4)));        \
+} while(0)
 /***/
 
 /****d* silcutil/SILCTypes/SILC_GET16_LSB
@@ -275,8 +322,10 @@ typedef SilcUInt32 * void *;
  * SOURCE
  */
 #define SILC_GET16_LSB(l, cp)                          \
+do {                                                   \
        (l) = ((SilcUInt32)(SilcUInt8)(cp)[0])          \
-           | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8)
+           | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8);    \
+} while(0)
 /***/
 
 /****d* silcutil/SILCTypes/SILC_GET32_LSB
@@ -292,10 +341,12 @@ typedef SilcUInt32 * void *;
  * SOURCE
  */
 #define SILC_GET32_LSB(l, cp)                          \
+do {                                                   \
        (l) = ((SilcUInt32)(SilcUInt8)(cp)[0])          \
            | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8)     \
            | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16)    \
-           | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24)
+           | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24);   \
+} while(0)
 
 /* Same as upper but XOR the result always. Special purpose macro. */
 #define SILC_GET32_X_LSB(l, cp)                                \
@@ -318,8 +369,10 @@ typedef SilcUInt32 * void *;
  * SOURCE
  */
 #define SILC_PUT16_MSB(l, cp)                  \
+do {                                           \
        (cp)[0] = l >> 8;                       \
-       (cp)[1] = l;
+       (cp)[1] = l;                            \
+} while(0)
 /***/
 
 /****d* silcutil/SILCTypes/SILC_PUT32_MSB
@@ -335,10 +388,12 @@ typedef SilcUInt32 * void *;
  * SOURCE
  */
 #define SILC_PUT32_MSB(l, cp)                  \
+do {                                           \
        (cp)[0] = l >> 24;                      \
        (cp)[1] = l >> 16;                      \
        (cp)[2] = l >> 8;                       \
-       (cp)[3] = l;
+       (cp)[3] = l;                            \
+} while(0)
 /***/
 
 /****d* silcutil/SILCTypes/SILC_PUT64_MSB
@@ -373,8 +428,10 @@ do {                                                               \
  * SOURCE
  */
 #define SILC_PUT16_LSB(l, cp)                  \
+do  {                                          \
        (cp)[0] = l;                            \
-       (cp)[1] = l >> 8;
+       (cp)[1] = l >> 8;                       \
+} while(0)
 /***/
 
 /****d* silcutil/SILCTypes/SILC_PUT32_LSB
@@ -390,10 +447,12 @@ do {                                                              \
  * SOURCE
  */
 #define SILC_PUT32_LSB(l, cp)                  \
+do {                                           \
        (cp)[0] = l;                            \
        (cp)[1] = l >> 8;                       \
        (cp)[2] = l >> 16;                      \
-       (cp)[3] = l >> 24;
+       (cp)[3] = l >> 24;                      \
+} while(0)
 /***/
 
 #endif /* SILCTYPES_H */