2

i have a cpp file say xyz.cpp, which contains long constants. now i need to change long constants to long long.

ex   
long a=0x00000001

to

long long a=0x0000000000000001

for future purpose. ( i use gcc compiler ) But when i do so, i got "integer value is to large to hold the long value" error. when browsed over internet, i got a suggestion like use,

long long a=0x0000000000000001ULL .

that worked fine. but the problem is i ve a jar file, that need to convert this .cpp file to .java. when it try to convert a .java file from .cpp file, it does not recognizes ULL.

now my question is

1, to this scenerio, is this anyway for my gcc compiler to make accept long long values, instead of adding ULL @ the end 2, or suggest me what should i do in .java file to accept that long long value (ULL) ( i know java has only long value that can hold long long value )

thanks in advance :)

Mat
  • 202,337
  • 40
  • 393
  • 406

3 Answers3

1

Since C++ won't compile as java without modifying the source, you could just strip the ULL/LL suffix (and change long long to long). You'll simply need to add this to the list of things to change when converting - I don't see the problem?

Erik
  • 88,732
  • 13
  • 198
  • 189
  • @Logeshwari Ram: By modifying the code that converts so that LL and ULL is handled correctly. – Erik Apr 15 '11 at 11:26
  • Hi, thank you for the answers. but there is .jar files, which converts my .cpp to .java for some purpose. i write long long values adding ULL @ the end, and yes, there is no error. but for my project to run, .jar file tries to convert .cpp to .java. Now as java does not recognize ULL, i'm facing the error in that. I need both the files to work perfectly with the long long values being assigned to them. But how shall i achieve that? – Logeshwari Ram Apr 15 '11 at 11:26
  • ya.. wen LL or ULL is added , the code works, but when converting .cpp to .java it fails.. is there any possible way to make the code run without using LL or ULL >? or anyway for the java file to accept that value? – Logeshwari Ram Apr 15 '11 at 11:28
  • @Logeshwari Ram: No. If the literal value doesn't fit into an integer, you must append `LL` for gcc to accept it. – Erik Apr 15 '11 at 11:29
0

So, what exactly are you trying to do, convert C++ code to Java?

Java does not have unsigned integer types, and the "long long" type from C++ also does not exist in Java. Java has the following integer types:

byte - 8-bit signed integer

short - 16-bit signed integer

int - 32-bit signed integer

long - 64-bit signed integer

(There is also char, which is technically a 16-bit unsigned integer, but which is meant to hold character data).

You could use BigInteger in Java if you need to work with numbers that do not fit in a long.

Jesper
  • 202,709
  • 46
  • 318
  • 350
  • Hi, thank you for the answers. but there is .jar files, which converts my .cpp to .java for some purpose. i write long long values adding ULL @ the end, and yes, there is no error. but for my project to run, .jar file tries to convert .cpp to .java. Now as java does not recognize ULL, i'm facing the error in that. I need both the files to work perfectly with the long long values being assigned to them. But how shall i achieve that? – Logeshwari Ram Apr 15 '11 at 11:25
  • What program is it that converts your C++ code to Java? Something will need to be changed in that program (ask the people who wrote it) to support this. – Jesper Apr 15 '11 at 11:28
0

long can hold 64-bits in Java, with signed behaviour where it matters. However this doesn't stop you storing unsigned 64-bit values in it. You need to write work arounds for certain operations, but +, -, *, == , != etc all work exactly the same.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130