Thread: Long long type

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    116

    Question Long long type

    I'm using Code::Block. I have this line of code:
    Code:
    define maxC 9000000000; //9.10^10
    int main(){
         long long min=maxC;
    }
    I think 9.10^10 doesn't exceed long long type. But, I don't know, when I'm compile this problem, there's a warning:
    <warning: integer constant is too large for 'long' type>
    Because, long type is just about 4.10^10 for unsign and 2.10^10 for sign integer. So, I cannot use it.

    So, how can I use long long type, and no above warning, please help me, please. (I think, they warning, mean sometimes, they will go wrong !!!)

    thanks

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    First you should not have the semicolon at the end of your define. Second what compiler are you using?
    I think 9.10^10 doesn't exceed long long type. But, I don't know, when I'm compile this problem, there's a warning:
    If you need to know the size of the variables a type can hold on your system you should look at the functions in the limits include file:
    Code:
    #include <iostream>
    #include <limits>
    
    int main(){
       std::cout << "Maximum value for long:      " << std::numeric_limits<long>::max() << std::endl;
       std::cout << "Maximum value for long long: " << std::numeric_limits<long long>::max() << std::endl;
    }

    Jim
    Last edited by jimblumberg; 09-22-2011 at 10:27 PM.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Put a LL for long long suffix at the integer.
    9000000000LL
    Devoted my life to programming...

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    >>define maxC 9000000000; //9.10^10
    const long long MaxC = 9000000000LL;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Code:
    static const long long MaxC = 9000000000LL;
    EDIT:
    It's ok, I just read that static is not necessary...
    Last edited by kmdv; 09-23-2011 at 04:55 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 04-23-2011, 08:40 PM
  2. Replies: 1
    Last Post: 10-11-2010, 01:53 AM
  3. Conver long to 8 byte array and back to long
    By plopes in forum C Programming
    Replies: 3
    Last Post: 04-01-2009, 12:39 AM
  4. STLport with MingW - Long Long error on project build
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 08-21-2006, 08:55 AM
  5. Is long long int a valid Data Type
    By shiv_tech_quest in forum C Programming
    Replies: 2
    Last Post: 11-12-2003, 08:59 AM