소스 검색

cJSON: prevent incompatible C and header versions

Introduces a preprocessor directive that aborts the compilation if the
version numbers in the header don't match with the numbers in the c
file.
Max Bruckner 8 년 전
부모
커밋
123bb1af7b
1개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      cJSON.c

+ 5 - 0
cJSON.c

@@ -58,6 +58,11 @@ const char *cJSON_GetErrorPtr(void)
     return (const char*) global_ep;
     return (const char*) global_ep;
 }
 }
 
 
+/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
+#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 2) || (CJSON_VERSION_PATCH != 1)
+    #error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
+#endif
+
 extern const char* cJSON_Version(void)
 extern const char* cJSON_Version(void)
 {
 {
     static char version[15];
     static char version[15];