Modify the int size STATIC_ASSERTS to work with CHAR_BITS!=8.
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Wed, 27 Jan 2016 16:24:33 +0000 (18:24 +0200)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Wed, 27 Jan 2016 16:49:53 +0000 (18:49 +0200)
This will still catch the most common bug of long int vs. long long int.
The uint8_t checks do not seem necessary, test for this will be added
in later commit.

pb.h

diff --git a/pb.h b/pb.h
index 8b9338c..b72e319 100644 (file)
--- a/pb.h
+++ b/pb.h
@@ -240,19 +240,13 @@ struct pb_field_s {
 PB_PACKED_STRUCT_END
 
 /* Make sure that the standard integer types are of the expected sizes.
 PB_PACKED_STRUCT_END
 
 /* Make sure that the standard integer types are of the expected sizes.
- * All kinds of things may break otherwise.. atleast all fixed* types.
+ * Otherwise fixed32/fixed64 fields can break.
  *
  * If you get errors here, it probably means that your stdint.h is not
  * correct for your platform.
  */
  *
  * If you get errors here, it probably means that your stdint.h is not
  * correct for your platform.
  */
-PB_STATIC_ASSERT(sizeof(int8_t) == 1, INT8_T_WRONG_SIZE)
-PB_STATIC_ASSERT(sizeof(uint8_t) == 1, UINT8_T_WRONG_SIZE)
-PB_STATIC_ASSERT(sizeof(int16_t) == 2, INT16_T_WRONG_SIZE)
-PB_STATIC_ASSERT(sizeof(uint16_t) == 2, UINT16_T_WRONG_SIZE)
-PB_STATIC_ASSERT(sizeof(int32_t) == 4, INT32_T_WRONG_SIZE)
-PB_STATIC_ASSERT(sizeof(uint32_t) == 4, UINT32_T_WRONG_SIZE)
-PB_STATIC_ASSERT(sizeof(int64_t) == 8, INT64_T_WRONG_SIZE)
-PB_STATIC_ASSERT(sizeof(uint64_t) == 8, UINT64_T_WRONG_SIZE)
+PB_STATIC_ASSERT(sizeof(int64_t) == 2 * sizeof(int32_t), INT64_T_WRONG_SIZE)
+PB_STATIC_ASSERT(sizeof(uint64_t) == 2 * sizeof(uint32_t), UINT64_T_WRONG_SIZE)
 
 /* This structure is used for 'bytes' arrays.
  * It has the number of bytes in the beginning, and after that an array.
 
 /* This structure is used for 'bytes' arrays.
  * It has the number of bytes in the beginning, and after that an array.