0

What type in Java corresponds to the long int type in C? It me interests in communication by creation of native of methods by means of JNI.

user1730626
  • 437
  • 1
  • 8
  • 16
  • 2
    `long int` in C can be `int` or `long` type in Java, depending on OS and platform. – nhahtdh Oct 21 '12 at 05:57
  • @nhahtdh I use solaris from Nexenta. – user1730626 Oct 21 '12 at 06:29
  • 1
    long int in C is a signed datatype, hence you can easily use it with long in Java. Had it been an unsigned datatype, you'd have to use the next higher datatype in Java, i.e. BigInteger. – Arham Oct 21 '12 at 06:36

1 Answers1

1

The answer depends on the size of the long datatype as supported by your C / C++ compiler. That depends on your hardware (32 bit versus 64 bit) and the compiler and compiler switches. What we can say for sure is that Java long is 64-bit signed and Java int is 32-bit signed.

This SO post deals with the size of C / C++ data types - What does the C++ standard state the size of int, long type to be? - and one of the Answers gives you a simple way to find the size of any given primitive type ... on your machine with your compiler and your compiler settings.

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • I use 64 bit Nexenta operating system. – user1730626 Oct 21 '12 at 06:51
  • For Nexenta: after read http://en.wikipedia.org/wiki/Nexenta_OS, it looks int and long are 32 bits. To have 64 bits int you have to say "long long int". A more detailed response at http://www.unix.org/version2/whatsnew/lp64_wp.html. – Aubin Oct 21 '12 at 08:48
  • @Aubin - however, the OP would be advised to check using `cout << "sizeof datatype = " << sizeof(long int) << endl;` – Stephen C Oct 21 '12 at 09:23
  • Yes, but today, it's very rare to see sizeof( int ) = 8 or sizeof( long ) = 8 (as shown by references in previous comment) – Aubin Oct 21 '12 at 09:25