[CMake] Question about the "logic" behind Utilities/KWIML/INT.h.in statement: @KWIML at _INT__VERIFY_TYPE(@KWIML at _INT_intptr_t, sizeof(void*));

Custin, Jay (CSC Sw Middleware) jay.custin at hpe.com
Thu Nov 5 13:28:19 EST 2015


>From INT.h.in:

   828  #if !defined(@KWIML at _INT_NO_INTPTR_T)
   829  @KWIML at _INT__VERIFY_TYPE(@KWIML at _INT_intptr_t,  sizeof(void*));
   830  #endif
   831  #if !defined(@KWIML at _INT_NO_UINTPTR_T)
   832  @KWIML at _INT__VERIFY_TYPE(@KWIML at _INT_uintptr_t, sizeof(void*));
   833  #endif

Now this statement blows up in the make Makefile process as follows:


cmIML_INT__VERIFY_TYPE(cmIML_INT_intptr_t,  sizeof(void*));
^
%CXX-E-NOTCOMPREDEC, declaration is incompatible with
          "int (*cmIML_INT_intptr_t__VERIFY__)[4U]" (declared at line 829)
at line number 829 in file LCL_ROOT:[cmake-3_3_2.Bootstrap_cmk.cmIML]INT.h;11



I wrote a simple C application to confirm the compiler's values, compiled-and-linked the application on both OpenVMS and Fedora Linux (x64) and noticed a discrepancy... 

ITAN1* ty foo.c
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main(void) {

   printf( "sizeof(intptr_t) = %d\n", sizeof(intptr_t));
   printf( "sizeof(uintptr_t) = %d\n", sizeof(uintptr_t));
   printf( "sizeof(void *) = %d\n", sizeof(void *));

   return EXIT_SUCCESS;
}


On OpenVMS this application displays the following:

ITAN1* r foo
sizeof(intptr_t) = 8
sizeof(uintptr_t) = 8
sizeof(void *) = 4 
sizeof(int *) = 4

and clearly sizeof(void *) = 4  < does NOT equal >  sizeof(intptr_t) = 8

On Fedora22 the exact same application displays the following:

[jpcustin at localhost ~]$ ./foo
sizeof(intptr_t) = 8
sizeof(uintptr_t) = 8
sizeof(void *) = 8 
sizeof(int *) = 8
[jpcustin at localhost ~]$


http://en.cppreference.com/w/c/types/integer describes intptr_t as: "integer type capable of holding a pointer"

http://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdint.h.html goes a little further:

Integer types capable of holding object pointers

The following type designates a signed integer type with the property that any valid pointer to void can be converted to this type, then converted back to a pointer to void, and the result will compare equal to the original pointer: intptr_t

The following type designates an unsigned integer type with the property that any valid pointer to void can be converted to this type, then converted back to a pointer to void, and the result will compare equal to the original pointer: uintptr_t


This begs the question...

Why does the CMake test rely on checking if sizeof(intptr_t) equals sizeof(void *) 

instead of sizeof(intptr_t) greater than or equal to sizeof(void *) 

(so can an intptr_t "hold" a void *)?

JayC


More information about the CMake mailing list