Search code examples
cjava-native-interfacesizeof

Is there any chance the sizeof operator returns 0?


I require to return a value of sizeof(some_t) from C to Java.

JNIEXPORT jint JNICALL blar(blar) {
#ifndef some_t
  return ?;
#else
  return sizeof(some_t);
#endif

As you can see I must return some value for the case the type is not even defined. So what's the best value for that case? 0 or -1? That's why I'm asking if there is any case that a sizeof operation returns 0 in any non-error case.


Solution

  • Objects in C always have a positive size, so no sizeof can never lead to 0.

    C doesn't allow empty struct or union types and also arrays must have a size that is bigger than 0. So there is no correct C type what soever that can return a value of 0.