No errors, but wont run...

This is a discussion on No errors, but wont run... within the C++ Programming forums, part of the General Programming Boards category; ok, thanks for your help, ive fixed it now I had declared it like this: Code: car car_details[300]; but when ...

  1. #16
    C++ Learner :D
    Join Date
    Mar 2004
    Posts
    69
    ok, thanks for your help, ive fixed it now

    I had declared it like this:

    Code:
    car car_details[300];
    but when i reduced it to:

    Code:
    car car_details[285];
    it worked.

  2. #17
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Thats one of those stange bugs that indicates a buffer overflow or uninitialized variables somewhere. I've once achieved something similar to this by using

    Code:
    for (i; i<10; i++) {
      get some memory here
    }
    without ever initalizing i. The bugs you get afterwards are strange and change when changing the program, sometimes they seem fixed but then they pop up again. Until you find the real cause.

    Salem might remember this.
    [code]

    your code here....

    [/code]

  3. #18
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > car car_details[285];
    Each car is just over 100 bytes
    printf( "sizeof car = %lu\n", (unsigned long)sizeof(car) );

    All cars are going to be 100*285, which is about 29K bytes.
    printf( "sizeof all cars = %lu\n", (unsigned long)sizeof(car_details) );

    My guess is, that adding all your other global variables takes this up to the max allowed by 16 bit compilers of 64K of data.

    The way you get round this is by
    1. choosing the large model (not small)
    2. putting global variables in different source files (then you get a max of 64K per variable), not 64K in total.

    I repeat my earlier comment - GET A DECENT COMPILER!.
    Modern 32 bit compilers have the same limit, but its like 2GB, not 64KB
    There is no possible justification for continuing to use that old fossil.

    > float price;//this is the one that makes it go wrong, it runs without it
    Only because it saved you a K or so of data space.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentations and casting errors
    By Joke in forum C Programming
    Replies: 3
    Last Post: 07-14-2008, 04:52 PM
  2. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 12:43 PM
  3. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 09:14 PM
  4. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 05:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21