FWIW, this experiment seems to run correctly on gcc 2.95.2 (returns 1) but not on gcc (GCC) 3.2.3 (mingw special 20030425-1) (returns 7)

Roger Wells, P.E.
221 Third St
Newport, RI 02840
401-847-4210 (voice)
401-849-1585 (fax)

Jeremy Jansma <jcojans1@yahoo.com>
Sent by: mingw-users-admin@lists.sourceforge.net

10/24/2003 11:24 AM
Please respond to mingw-users

        To:        mingw-users@lists.sourceforge.net
        Subject:        [Mingw-users] Newbie problem: Sample code runs correctly in MSVC but not MinGW


I've just begun experimenting with MinGW, and I ran
into a problem with a small program I wrote for a
class a few years back.

The code simply uses a recursive function to examine a
small array of integers to find the smallest element.
I have no problems compiling this code in MSVC, and
the executable correctly displays the value '1'. When
I compile this code in MinGW however, the executable
incorrectly displays the value '7'. Could someone
please take a quick look at this code and help me
determine why this is happening?

I tried using 'gdb' to help debug the code, but I
didn't get anywhere.

On a side note, are there any good (easy to use)
editors/debuggers out there that I could use in
combination with MinGW?

Thanks in advance for your help,


#include <iostream>
#include <string>
using namespace std;

const int recursiveMinimum(int Array[], int Length) //
check use of const
                // if Length is less than or equal to zero exit
function and return -1
                // (invalid array)
                if(Length <= 0)
                                 return -1;                

                static int SmallestElement = 0;                 // initialize
SmallestElement to first element
                static int value = 0;                 // initialize value to equal

                // if value equals NULL or array element is less than
                if(value == 0 || Array[Length - 1] < value)
                                 value = Array[Length - 1];                 // value equals value at
array element
                                 SmallestElement = Length - 1;                 // SmallestElement
equals element
                // if array is of length 1
                if(Length == 1)
                                 return SmallestElement;                 // return SmallestElement
                // call itself with one less element
                recursiveMinimum(Array, --Length);                

int main()
                int Ozz[] = {80, -1, 9};
                int size = 3;
                int smallest = 0;

                smallest = recursiveMinimum(Ozz, size);

                cout << "Smallest element = " << smallest << endl;

                return 0;

Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
MinGW-users mailing list

You may change your MinGW Account Options or unsubscribe at: