help about assign a max unsigned int64 value compilable with adroid ndk

1,010 views
Skip to first unread message

sall...@gmail.com

unread,
Sep 8, 2009, 10:26:38 AM9/8/09
to android-ndk
Hi,

I want to set a u_int64_t variable with the maximum unsigned 64 bit
integer, that is, 18446744073709551614,
but compile with ndk get a error,
I only can set it with 4294967295.
How to avoid such issue?
Thanks for any help.

ckh

Jack Palevich

unread,
Sep 8, 2009, 1:56:36 PM9/8/09
to andro...@googlegroups.com
On ARM processors the size of an int is 32 bits, so the size of a plain undecorated integer constant is also 32 bits.

For unsigned long constants I think you need to add the letters "ul" at the end of the constant:

18446744073709551614ul

fadden

unread,
Sep 8, 2009, 3:34:54 PM9/8/09
to android-ndk
On Sep 8, 10:56 am, Jack Palevich <jack...@google.com> wrote:
> On ARM processors the size of an int is 32 bits, so the size of a plain
> undecorated integer constant is also 32 bits.
> For unsigned long constants I think you need to add the letters "ul" at the
> end of the constant:
>
> 18446744073709551614ul

C longs are 32-bit on our platform, so 64-bit is a "long long". Use
"ULL".

(In Java it's just 'L', because Java longs are 64 bits.)

Note also that 18446744073709551614 is 0xfffffffffffffffe. ULLONG_MAX
is 18446744073709551615ULL.

Pawel Veselov

unread,
Sep 8, 2009, 5:09:14 PM9/8/09
to andro...@googlegroups.com

Umm, isn't long on 32bit arch is also 32bit? 64bit is 'long long', and the constant suffix for 64 bit constants will be 'LL', or 'ULL' for unsigned. Alternatively, you can stick signed -1 into unsigned 64bit, to get a max val.

[vps@medusa]~/cprog$ cat ull.c

#include <stdio.h>

int main(int argc, char ** argv) {

    unsigned long long p = -1LL;
    fprintf(stdout, "val: %llu, %llx\n", p, p);

    return 0;

}

/Users/vps/Android/ndk/android-ndk-1.5_r1/build/prebuilt/darwin-x86/arm-eabi-4.2.1/bin/arm-eabi-gcc -o ull -isystem/Users/vps/Android/ndk/android-ndk-1.5_r1/build/platforms/android-1.5/arch-arm/usr/include -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DSK_RELEASE -DNDEBUG -UDEBUG -march=armv5te -mtune=xscale -msoft-float -mthumb-interwork -fpic -fno-exceptions -ffunction-sections -funwind-tables -fmessage-length=0 -Bdynamic -Wl,-T,/Users/vps/Android/ndk/android-ndk-1.5_r1/build/prebuilt/darwin-x86/arm-eabi-4.2.1/arm-eabi/lib/ldscripts/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -Wl,--no-undefined -Wl,-rpath-link=/Users/vps/Android/ndk/android-ndk-1.5_r1/build/platforms/android-1.5/arch-arm/usr/lib -L/Users/vps/Android/ndk/android-ndk-1.5_r1/build/platforms/android-1.5/arch-arm/usr/lib -nostdlib /Users/vps/Android/ndk/android-ndk-1.5_r1/build/platforms/android-1.5/arch-arm/usr/lib/crtend_android.o /Users/vps/Android/ndk/android-ndk-1.5_r1/build/platforms/android-1.5/arch-arm/usr/lib/crtbegin_dynamic.o /Users/vps/Android/ndk/android-ndk-1.5_r1/build/prebuilt/darwin-x86/arm-eabi-4.2.1/lib/gcc/arm-eabi/4.2.1/libgcc.a -lc -lm ull.c

# /data/misc2/ull
val: 18446744073709551615, ffffffffffffffff
Reply all
Reply to author
Forward
0 new messages