[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 14:35:41 EST 2015


Probably a moot question at this point... I posed the same question to some of the language/compiler experts at HPE and got the following explanation:

Looking quickly, I suspect that he is not using the /pointer=long qualifier at compile time.
The default pointer size is 32-bit (4 bytes), but there are a few different ways to get 64-bit pointers.  The /pointer=long is the easiest.
Hope this helps.

XXXX05>hpcc/pointer=long ptr_test
XXXX05>link ptr_test
XXXX05>r ptr_test
sizeof(intptr_t) = 8
sizeof(uintptr_t) = 8
sizeof(void *) = 8
sizeof(int *) = 8
XXXX05>


-----Original Message-----
From: Custin, Jay (CSC Sw Middleware) 
Sent: Thursday, November 05, 2015 1:28 PM
To: cmake at cmake.org
Subject: Question about the "logic" behind Utilities/KWIML/INT.h.in statement: @KWIML at _INT__VERIFY_TYPE(@KWIML at _INT_intptr_t, sizeof(void*));

>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