ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
`long long int` was introduced by ISO 9899/1999, pass "-std=c99" to gcc.
long long int is also supported by the GNU extensions (gnu89 & gnu99) whereof gnu89 is used by default IF no -std= option is given on the command-line. But yes, -std=c99 should be safe
I can't reproduce this error, neither on a 32-bit nor a 64-bit system. Some thoughts:
* maybe you are using an old C library
* maybe you are using an old & buggy compiler
long long int is also supported by the GNU extensions (gnu89 & gnu99)
Thank you for the information. I suppose I really should read the GCC manual one of these days.
I don't really understand what the OP means by "can't insert a value greater than 2^31-1..". How are you attempting to do this and what makes you declare that you failed?
Last edited by carbonfiber; 01-12-2010 at 11:54 AM.
The last number is negative because the comparison is done before the increment. If you want no negative number to be displayed then change the condition of your while loop to:
As a rule of thumb, don't assume that a particular data type is of a particular size. gcc runs on multiple dozens of hardware platforms, and it must make an "appropriate" decision for each.
There are standard data-type definitions available which stipulate that the variable will be of "at least" a certain size and/or numeric capacity. If your application needs to make such assertions, it should use one of those types. But if it does not, then it should leave all such matters to the discretion of the compiler.
why can't I insert a value greater than 2^31-1 (ie 32bit)
in a long long type variable.
By this did you mean that you are having difficulty assigning a literal greater than 32bits? if so see my code (post 8) and notice the suffix LL which is essential to add numbers greater than 32 bits. Refer to the link I provided (post 10) from the gcc documentation on the long long data type.
I don't know if you caught what graemef said, but he probably hit the nail right on the head:
Quote:
By this did you mean that you are having difficulty assigning a literal greater than 32bits? if so see my code (post 8) and notice the suffix LL which is essential to add numbers greater than 32 bits. Refer to the link I provided (post 10) from the gcc documentation on the long long data type.
Every time you use a long long in an expression with an "int", or with a literal that doesn't explicitly use the "LL" suffix, you risk the entire expression being DOWNCAST to 32-bits.
I'm pretty sure that if you review all your code, you'll confirm that's what's happening.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.