tabled: use LL to indicate 64-bit constant
PATCH 1/1 tabled: use LL to indicate 64-bit constant
All integer constants are squashed into ints (i.e. 32-bit) unless you specify otherwise.
--- server/util.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
server/util.c +1 -1
@@ -328,7 +328,7 @@ int objid_init(uint64_t *obj_count, struct tabledb *tdbp)exit (1 );/* Quit before something unknown blows up. */ } -if (objcount &0xff00000000000000 ) { +if (objcount &0xff00000000000000ll ) {applog (LOG_ERR ,"Dangerous objid %llX\n" , (unsigned long long ) objcount);return -1 ;
Signature · 1 line
1.6.2.5
Quoted 13 lines · Colin McCabe
All integer constants are squashed into ints (i.e. 32-bit) unless you specify otherwise.
Signed-off-by Colin McCabe<[email protected]>--- server/util.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)server/util.c +0
-0
server/util.c int objid_init(uint64_t *obj_count, struct tabledb *tdbp) · line 331
Quoted 5 lines
server/util.c +1
-1@@ -328,7 +328,7 @@ int objid_init(uint64_t *obj_count, struct tabledb *tdbp)exit (1 );/* Quit before something unknown blows up. */ } -if (objcount&0xff00000000000000 ) { +if (objcount&0xff00000000000000ll ) {
hmmm, I thought it was type-promoted as needed. I will check C99 when I've had some sleep :)
Quoted 13 lines · Colin McCabe
All integer constants are squashed into ints (i.e. 32-bit) unless you specify otherwise.
Signed-off-by Colin McCabe<[email protected]>--- server/util.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)server/util.c +0
-0
server/util.c int objid_init(uint64_t *obj_count, struct tabledb *tdbp) · line 332
Quoted 6 lines
server/util.c +1
-1@@ -328,7 +328,7 @@ int objid_init(uint64_t *obj_count, struct tabledb *tdbp)exit (1 );/* Quit before something unknown blows up. */ } -if (objcount&0xff00000000000000 ) { +if (objcount&0xff00000000000000ll ) { applog(LOG_ERR, "Dangerous objid %llX\n",
Yep, "The type of an integer constant is the first of the corresponding list in which its value can be represented." (C99 6.4.4.1 paragraph 5)
Were you seeing a problem here?
Jeff
util.c: In function ‘objid_init’:
util.c:331: warning: integer constant is too large for ‘long’ type
with
[cmccabe@stargazer tabled]$ gcc --version
gcc (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)
Now that I wrote a little test program, I can see that gcc handles the constant correctly. It still issues a warning for some reason. I guess gcc's C99 support is not perfect.
Colin
Quoted 36 lines · Jeff Garzik
Quoted 15 lines · Colin McCabe
All integer constants are squashed into ints (i.e. 32-bit) unless you specify
otherwise.Signed-off-by Colin McCabe<[email protected]>--- server/util.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)server/util.c +0
-0server/util.c int objid_init(uint64_t *obj_count, struct tabledb · line 334
Quoted 8 lines
server/util.c +1
-1@@ -328,7 +328,7 @@ int objid_init(uint64_t *obj_count, struct tabledb *tdbp)exit (1 );/* Quit before something unknown blows up. */ } -if (objcount&0xff00000000000000 ) { +if (objcount&0xff00000000000000ll ) { applog(LOG_ERR, "Dangerous objid %llX\n",Yep, "The type of an integer constant is the first of the corresponding list in which its value can be represented." (C99 6.4.4.1 paragraph 5)
Were you seeing a problem here?
Jeff
Quoted 11 lines · Colin McCabe
util.c: In function ‘objid_init’:
util.c:331: warning: integer constant is too large for ‘long’ typewith
[cmccabe@stargazer tabled]$ gcc --version
gcc (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)Now that I wrote a little test program, I can see that gcc handles the constant correctly. It still issues a warning for some reason. I guess gcc's C99 support is not perfect.
Is this on a 32-bit on 64-bit compiler platform?
Because Linux does
#if __WORDSIZE == 64 typedef unsigned long int uint64_t; #else __extension__ typedef unsigned long long int uint64_t; #endif
which causes the comparison type (uint64_t objcount) to vary between 32-bit and 64-bit platforms, even if the number of bits used to store it remains the same.
Strange...
Jeff
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#if 1
#define X 0xff00000000000000
#else
#define X x
#endif
int main (int argc, char *argv[])
{
uint32_t x = 0;
if (__builtin_types_compatible_p (typeof (X), int))
printf("type: int\n");
else if (__builtin_types_compatible_p (typeof (X), unsigned int))
printf("type: unsigned int\n");
else if (__builtin_types_compatible_p (typeof (X), long))
printf("type: long\n");
else if (__builtin_types_compatible_p (typeof (X), unsigned long))
printf("type: unsigned long\n");
else if (__builtin_types_compatible_p (typeof (X), long long))
printf("type: long long\n");
else if (__builtin_types_compatible_p (typeof (X), unsigned long long))
printf("type: unsigned long long\n");
else
printf("type: unknown\n");
(void) x;
return 0;
}It's an old 32-bit machine.
I also notice that -std=gnu99 makes the warning go away.
I don't think that "long long" existed in C89, except as a compiler-specific extension.
I guess that explains the error: gcc tries to promote the integer constant to a long, finds that a long isn't big enough (because we're on 32 bit), and then issues a warning.
And then it promotes to the gcc-specific long long type.
Colin
Quoted 35 lines · Jeff Garzik
Quoted 4 lines · Colin McCabe
util.c: In function ‘objid_init’:
util.c:331: warning: integer constant is too large for ‘long’ typeQuoted 8 lines
with
[cmccabe@stargazer tabled]$ gcc --version
gcc (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)Now that I wrote a little test program, I can see that gcc handles the constant correctly. It still issues a warning for some reason. I guess gcc's C99 support is not perfect.
Is this on a 32-bit on 64-bit compiler platform?
Because Linux does
#if
__WORDSIZE== 64
typedef unsigned long intuint64_t;
#else
__extension__
typedef unsigned long long int uint64_t;
#endifwhich causes the comparison type (
uint64_tobjcount) to vary between 32-bit and 64-bit platforms, even if the number of bits used to store it remains the same.Strange...
Jeff