This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

ingres: problem locating heap


I am trying to port ingres. Somebody done it before?
Ingres is originally written for DEC PDP, maybe the location of stack 
and heap are reveresed there.
I have probems with this piece of code:

xfree(cp)
char		*cp;
{
    extern 			end;	/* break (II) */
    register char		*lcp, *lend, *lacp;

    lcp = cp;
    lacp = (char *)&cp;
    lend = (char *)&end;
    if (lcp >= lend && lcp < lacp)	/* make sure its in heap */
    {
        free(lcp);
        return (0);
    }
    return (1);
}

"end" results in link-error, but even if I create "end" somewhere on 
the heap the if-statement looks wrong: I checked it with this code:

#include <iostream.h>

char* end;

void f(char* cp)
{
    cout << "adres end: " << (void*)end << endl;
    cout << "adres stack: " << (void*)&cp << endl;
    if ((void*)end < (void*)&cp)
        cout << "heap lower than stack" << endl;
    else cout << "heap higher than stack" << endl;
}

int main()
{
    char c;
    end = new char;
    f(&c);
    delete end;
    return 0;
}

Output: "heap higher than stack".

Is it true that stack and heap are reversed in PDP?
What happens when I replace xfree() by free(), I mean: is it 
really harmless to free something not allocated on the heap? free() 
in next program doesn't do anything.

#include <stdlib.h>

int main()
{
    char* s = "The string\n";

    printf("%s", s);
    free (s);
    printf("%s", s);
    return 0;
}
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]