Thread: Diff compiler == diff program????

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    for (int b = 1; b <= Kth_integer; ++b) {
    ifile >> inums[b];

    Once a program is invalid, the rest of the program is also invalid. You access an element which is not inside the array. The fact that all programs with such errors do not automatically fail is what makes debugging so interesting at times.

    At this point, you can't know what will happen - sometimes it works (or more likely seems to for a while at least), other times it does something completely different.

    In fact, you may get gpp to fail if you compile with -O say (the optimiser). This rearranges the code/data, and this may expose the problem. Then again it might not.

    This is a sure sign that you have a problem. A correct program should produce the same answer with a correct compiler.
    Certainly any program which sticks to ANSI only features, when compiled with an ANSI compliant compiler (or one which claims to be). Even then, there can be the occasional obscurity to trip you up.

    > She uses turbo
    This isn't an ANSI compliant compiler, so you're already on a slightly slippy slope.

  2. #17
    I bet it would work if you have ios:ut, ios::binary. If this doesnt work, seek to the beginning. I always use dev, and i have not had any problems. I frequently have files written where position really counts and have yet to have compiler (as opposed to programmer) problems.
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    MinGW on XP

  3. #18
    Evil Member
    Join Date
    Jan 2002
    Well salem, correcting the out of range access by defining the array as nums[Kth_iteger+1] did not correct the problem in Dev-C++. It did not change the result of either compilation (both times on both compilers w/o errors) or change the effect (gpp does it right, dc++ does nothing at all).

    I think it might be the ios::in part. I have never had problems passing an ios::in to an ostream to put the pointer at the start, but I have only done this kind of thing on gpp, which I prefer for it's directness.

    I'll try using the seek functions. Can anyone tell me the syntax of seeking the put pointer to where the get pointer is in an fstream object? I haven't been in depth on ios yet.

  4. #19
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Try using a fstream declaration.

    fstream file("file.txt", ios::in, ios:ut)

  5. #20
    Evil Member
    Join Date
    Jan 2002

    Found it!!!

    I did some snooping on msdn, and found out that while passing an ios::in to an ofstream is legal, you have to at least pass an ios::out to it. So an ostream with ios::out | ios::in is opened for output at the beginning.

    I guess gpp waives this, but Dev-C++ need the ios::out. With that, and the array bound check, it works!

  6. #21
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    >fstream file("file.txt", ios::in, ios:ut)

    you cant do that there should be a | instead of the , between ios::in and ios:ut

  7. #22
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    both are acceptable. there are three arguements, the last two are defaults, though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework help
    By mkdl750 in forum C Programming
    Replies: 45
    Last Post: 07-17-2008, 09:44 PM
  2. Tic Tac Toe Program Question
    By Unknowntoyou000 in forum C++ Programming
    Replies: 24
    Last Post: 04-10-2008, 08:55 PM
  3. Looking for feedback on program segment
    By avron in forum C++ Programming
    Replies: 4
    Last Post: 05-07-2007, 04:38 PM
  4. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  5. swapping elements in a 2D array
    By axon in forum C++ Programming
    Replies: 9
    Last Post: 03-10-2003, 02:18 PM