LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-27-2008, 02:53 PM   #1
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Rep: Reputation: 33
Post 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
 
Old 06-27-2008, 03:41 PM   #2
wget
LQ Newbie
 
Registered: Apr 2008
Distribution: Slackware 12.0 Kernel 2.6.25, LFS 2.6.25.1 Kernel
Posts: 25

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

Code:
else if( size<=1099511627776L )
	{
		
	}
 
Old 06-27-2008, 04:11 PM   #3
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by vxc69 View Post
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.
 
Old 06-27-2008, 04:46 PM   #4
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Original Poster
Rep: Reputation: 33
Thanks guys, it worked! Wasn't aware of the L qualifier.
 
  


Reply

Tags
compile, error, int, java, numbers, type


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Type Java Arrays InJesus Programming 3 01-07-2006 05:09 PM
Quick Java question Nylex Programming 2 01-26-2004 12:44 PM
quick question - java Laptop2250 Programming 2 10-15-2003 09:56 PM
Quick Java plug-in question Tyir Linux - Newbie 4 10-09-2003 01:58 PM
Quick question: Does Java 1.4.2 unstable in your PC? codec Linux - Software 3 09-16-2003 11:24 AM


All times are GMT -5. The time now is 04:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration