Thread: Doesnt fseeko64 work with negative offsets?

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    76

    Some strange casting problem

    Im trying to use fseeko64. It works perfectly when using positive offsets, but whenever i use a negative offset something strange happens and my program creates huge files (after+/- 15 secs and 2.5GB data i killed my program)

    Am i doing something wrong? Cant fseeko64 be used with negative values?

    Im on winxp with mingw compiler



    EDIT
    Sry for the title-edit

    this is really weird stuff. fseeko64 DOES work, the values i pass to it are wrong:
    Code:
                off64_t os64;
    
                os64 = sizeof(int);
                os64 = -os64; // works
    
                os64 = -sizeof(int); // os64  gets a VERY big value
    Why does os64 = -sizeof(int) doesnt work?
    Last edited by johny145; 08-01-2005 at 11:54 AM.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Integral Promotions

    sizeof returns an unsigned value that's smaller than an off64_t

    Code:
    os64 = -(off64_t)sizeof(int);
    gg

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    76
    Thx for the info.

    It was a really nasty bug to find. Im wondering, shouldn't the compiler give an error when going from unsigned int to long long.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dlopen, dlsym does not work in Linux as expected
    By balakv in forum C Programming
    Replies: 2
    Last Post: 04-03-2007, 12:44 AM
  2. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  3. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  4. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  5. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM