Find the answer to your Linux question:
Results 1 to 8 of 8
On linux 2.4, I could do the following with no warnings or errors. On Linux 2.6 with gcc, it compiles but gives a warning. The created program works. On Linux ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    5

    off_t problem with g++

    On linux 2.4, I could do the following with no warnings or errors.
    On Linux 2.6 with gcc, it compiles but gives a warning. The created program works.
    On Linux 2.6 with g++, it fails compile with an error.

    What gives? Anyone know?

    Thx,

    Jim


    My compile is like this:
    cc offt.c -D_LARGE_FILES -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -o offt
    g++ offt.c -D_LARGE_FILES -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -o offtp


    #ifndef WIN32
    #include <unistd.h>
    #else
    #endif
    #include <stdlib.h>
    #include <stdio.h>

    int main( int argc, char *argv[] )
    {
    #ifdef WIN32
    __int64 i64;
    #else
    off_t offt = 0;
    long long lg = 0;
    #endif

    #ifdef WIN32
    i64 = 9223372036854775807;
    printf( "i64=%I64d, szi64=%d\n", i64, sizeof(i64) );
    #else
    offt = 9223372036854775807;
    lg = 9223372036854775807;
    printf( "offt=%lld, lg=%lld, szofft=%d, szlg=%d\n", offt, lg, sizeof(offt), sizeof(lg) );
    #endif
    }

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Whats the error/warning?

  3. #3
    Just Joined!
    Join Date
    Apr 2008
    Posts
    5
    Oh right! The warning/error....

    With cc:
    offt.c: In function ΓÇÿmainΓÇÖ:
    offt.c:21: warning: integer constant is too large for ΓÇÿlongΓÇÖ type
    offt.c:22: warning: integer constant is too large for ΓÇÿlongΓÇÖ type

    With g++:
    offt.c:21: error: integer constant is too large for ΓÇÿlongΓÇÖ type
    offt.c:22: error: integer constant is too large for ΓÇÿlongΓÇÖ type

    It actually shows the funny characters too.

    Jim

  4. #4
    Just Joined!
    Join Date
    Apr 2008
    Posts
    5
    And gcc -v yields: gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)

  5. #5
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    try ending your long long const 9223372036854775807 with ll

    example 9223372036854775807ll;

    ll are the letters LL

    This tells the compiler that the integers are long long consts

  6. #6
    Just Joined!
    Join Date
    Apr 2008
    Posts
    5
    Nope. Ending with LL doesn't help.

    Thx anyway,

    Jim

  7. #7
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Thats odd...I copied your code and tried compiling and received the same errors as you, so I appened LL to the long long consts and the compile errors dissappeared.

    note I only compiled it in C not C++

  8. #8
    Just Joined!
    Join Date
    Apr 2008
    Posts
    5
    Oops, my bad. I only did the LL on the off_t variable assignment.
    Doing it on both made it work.

    Thx,

    Hate it when they just change the compiler (or the includes) like that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...