signed and unsigned int

Discussion in 'C Programming' started by jacob navia, Aug 11, 2004.

  1. jacob navia

    jacob navia Guest

    A signed int can contain up to 2Gig, 2 147 483 648, to be exact.

    Since The Mars rovers landed, I have been storing the
    photographs in two directories, Spirit and Opportunity. I had
    more than 18 000 files in a single directory. Without being
    aware of it, I crossed the 2 147 483 648 border last week.

    Nothing happens, if you do not attempt to read all files in the directory,
    or even worst, copy them to another drive.

    Worried by mysterious disk errors, I tried to save my work. When making
    the copy however, there was an error when the copy arrived at an image
    and could not read it.

    Foolish me, I tried to copy the file again.

    That was it: the disk started to make a periodic mechanical noise, and
    it was GONE ALONG WITH ALL MY DATA IN THE DISK!!!!!!!!!!!!!!!!!!!!!

    Why?

    When a signed integer is increased beyond 2147483648, it becomes NEGATIVE.
    This means that the system will issue a NONSENSE movemevent order to the
    read heads, destroying the disk instantly.

    I was lucky. I had a full backup of the mars data in my linux system. Ahh
    Microsoft.
    I fired up the linux machine running ext2 file system. I issued the order to
    copy
    the files, and started doing other things during the copy.

    When the amount of data transmitted arrived at approx 2GB, I heared with
    horror that
    the disk started doing the SAME repeating mechanical noise and my linux
    system
    WAS GONE, I HAVE LOST several months of work without any means of getting
    my data back.

    Signed integer can contain up to 2147483648 bytes. Not a single byte more.

    I have developed a compile time switch to check for overflows within
    lcc-win32 and
    posted here a message, several weeks ago. Nobody cared to answer.

    SHIT !!!!!!!!!!!

    C is a nice language in which to write file systems. But IT WOULD BE BETTER
    TO
    BE CAREFUL WITH THOSE "int" s OK?

    You do not believe me?

    Try it. Make several directories with several thousand files of 100-200K
    each, until
    you get more than 2GB.

    But backup your drive first...

    jacob
     
    jacob navia, Aug 11, 2004
    #1
    1. Advertising

  2. (jacob navia) writes:
    > A signed int can contain up to 2Gig, 2 147 483 648, to be exact.

    [snip]

    Did you mean to post this twice?

    Followups redirected to /dev/null; please reply to the original post,
    so we don't get two distinct threads.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Aug 11, 2004
    #2
    1. Advertising

  3. jacob navia

    Neil Kurzman Guest

    jacob navia wrote:

    > A signed int can contain up to 2Gig, 2 147 483 648, to be exact.
    >
    > Since The Mars rovers landed, I have been storing the
    > photographs in two directories, Spirit and Opportunity. I had
    > more than 18 000 files in a single directory. Without being
    > aware of it, I crossed the 2 147 483 648 border last week.
    >
    > Nothing happens, if you do not attempt to read all files in the directory,
    > or even worst, copy them to another drive.
    >
    > Worried by mysterious disk errors, I tried to save my work. When making
    > the copy however, there was an error when the copy arrived at an image
    > and could not read it.
    >
    > Foolish me, I tried to copy the file again.
    >
    > That was it: the disk started to make a periodic mechanical noise, and
    > it was GONE ALONG WITH ALL MY DATA IN THE DISK!!!!!!!!!!!!!!!!!!!!!
    >
    > Why?
    >
    > When a signed integer is increased beyond 2147483648, it becomes NEGATIVE.
    > This means that the system will issue a NONSENSE movemevent order to the
    > read heads, destroying the disk instantly.
    >
    > I was lucky. I had a full backup of the mars data in my linux system. Ahh
    > Microsoft.
    > I fired up the linux machine running ext2 file system. I issued the order to
    > copy
    > the files, and started doing other things during the copy.
    >
    > When the amount of data transmitted arrived at approx 2GB, I heared with
    > horror that
    > the disk started doing the SAME repeating mechanical noise and my linux
    > system
    > WAS GONE, I HAVE LOST several months of work without any means of getting
    > my data back.
    >
    > Signed integer can contain up to 2147483648 bytes. Not a single byte more.
    >
    > I have developed a compile time switch to check for overflows within
    > lcc-win32 and
    > posted here a message, several weeks ago. Nobody cared to answer.
    >
    > SHIT !!!!!!!!!!!
    >
    > C is a nice language in which to write file systems. But IT WOULD BE BETTER
    > TO
    > BE CAREFUL WITH THOSE "int" s OK?
    >
    > You do not believe me?
    >
    > Try it. Make several directories with several thousand files of 100-200K
    > each, until
    > you get more than 2GB.
    >
    > But backup your drive first...
    >
    > jacob


    1. This is OT
    2. an "int" can be 16, 32 or 64 bits. It is the compiler / OS / CPU decision.

    3. choice of signed unsigned is the programmers choice.
    4. fatal overflows are the programmers fault.
     
    Neil Kurzman, Aug 12, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Siemel Naran

    convert signed int to unsigned int

    Siemel Naran, Nov 28, 2004, in forum: C++
    Replies:
    3
    Views:
    34,153
    Ioannis Vranos
    Nov 29, 2004
  2. G Fernandes
    Replies:
    2
    Views:
    503
    Lawrence Kirby
    Feb 16, 2005
  3. Alex
    Replies:
    3
    Views:
    650
    Michael Mair
    Apr 26, 2006
  4. Fore
    Replies:
    29
    Views:
    15,409
    Rashad
    Sep 21, 2008
  5. pozz
    Replies:
    12
    Views:
    762
    Tim Rentsch
    Mar 20, 2011
Loading...

Share This Page