hiroyuki-sato / ucx

Unified Communication X (mailing list - https://elist.ornl.gov/mailman/listinfo/ucx-group):
http://www.openucx.org
Other
2 stars 0 forks source link

UCS_STATIC_ASSERT memo #22

Open hiroyuki-sato opened 5 years ago

hiroyuki-sato commented 5 years ago
#include <stdio.h>

#define UCS_STATIC_ASSERT(_cond) \
     switch(0) {case 0:case (_cond):;}

int main(){
  UCS_STATIC_ASSERT(sizeof(int) == sizeof(char)); // ERROR
  UCS_STATIC_ASSERT(sizeof(int) == sizeof(int));  // OK
}
test.c: In function ‘main’:
test.c:4:24: error: duplicate case value
      switch(0) {case 0:case (_cond):;}
                        ^
test.c:7:3: note: in expansion of macro ‘UCS_STATIC_ASSERT’
   UCS_STATIC_ASSERT(sizeof(int) == sizeof(char));
   ^~~~~~~~~~~~~~~~~
test.c:4:17: note: previously used here
      switch(0) {case 0:case (_cond):;}
                 ^
test.c:7:3: note: in expansion of macro ‘UCS_STATIC_ASSERT’
   UCS_STATIC_ASSERT(sizeof(int) == sizeof(char));
   ^~~~~~~~~~~~~~~~~