LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Java: Quick question about primitive data type long. (https://www.linuxquestions.org/questions/programming-9/java-quick-question-about-primitive-data-type-long-652147/)

vxc69 06-27-2008 02:53 PM

Java: Quick question about primitive data type long.
 
I have a variable of type long (primitive, so range is 2^63) called size.

I have the following code that is giving me an error:

Code:

else if(size<=1099511627776)
        {
               
        }

I'm getting the error "The literal 1099511627776 of type int is out of range". So it seems that when comparing size with 1099511627776, it's comparing data type long with an integer.

How do I overcome this problem?

I tried placing the value I'm trying to compare into another long variable, but I can't assign the value 1099511627776 to it because I get the same error.


Thanks for any guidance,
vxc

wget 06-27-2008 03:41 PM

Use an L qualifier, I'm guessing it's treating the literal value as a normal int so:

Code:

else if( size<=1099511627776L )
        {
               
        }


David1357 06-27-2008 04:11 PM

Quote:

Originally Posted by vxc69 (Post 3197237)
How do I overcome this problem?

wget is right. You have to declare large numbers using the "L" qualifier or you get a compiler error like that. Otherwise, the compiler thinks you are trying to jam that much information into its default type (int) and it will not fit.

vxc69 06-27-2008 04:46 PM

Thanks guys, it worked! Wasn't aware of the L qualifier. :)


All times are GMT -5. The time now is 08:17 AM.