Thread: long long int with g++/MinGW

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    1

    long long int with g++/MinGW

    Hi,

    I'm trying to use the "long long int" type, but I seem to be having some trouble. I'm using g++ (version 3.4.5, 2006, as far as I can tell), in MinGW, programming in the NetBeans 6.1 IDE. The trouble is that the compiler recognizes "long long int" (and its variations), but doesn't seem to be able to actually deal with them - arithmetic and printing show obvious errors. For example:

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <limits.h>
    
    int main(){
       printf("sizeof(long long): %d, Min: %lld, Max: %lld\n",
                 sizeof(long long), LLONG_MIN, LLONG_MAX);
       return 0;
    }
    My result is:

    Code:
    sizeof(long long): 8, min: 0, max -2147483648
    Anybody have any idea what might be causing this? I needses my 8-byte integers, yes I does...

    Thanks much in advance

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should use %I64d instead of %lld as MinGW uses MSVCRT. Keep in mind that with respect to the current C++ standard long long is a compiler extension. Also, you should use <cstdlib>, <cstdio> and <climits>, and note that printf is in the std namespace.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Also take note that you really should be using std::cout instead of printf. Is there a reason you use printf?
    Or perhaps you posted in the wrong section (ie this is C code)?
    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.

  4. #4
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    Quote Originally Posted by laserlight View Post
    You should use %I64d instead of %lld as MinGW uses MSVCRT. Keep in mind that with respect to the current C++ standard long long is a compiler extension. Also, you should use <cstdlib>, <cstdio> and <climits>, and note that printf is in the std namespace.
    Sadly gcc isn't strict about namespace std on C headers even with the C++ style inclusion.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  2. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 06:40 PM
  5. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM