delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/04/18/05:32:39

From: tjoen AT dds DOT nl
Subject: ingres: problem locating heap
18 Apr 1998 05:32:39 -0700 :
Message-ID: <199804171659.SAA19471.cygnus.gnu-win32@k9.dds.nl>
Mime-Version: 1.0
To: gnu-win32 AT cygnus DOT com

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 AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019