From: "Michael Schuster" Organization: LS f. Elektr. Energieversorgung To: djgpp AT delorie DOT com Date: Mon, 8 Jul 1996 16:58:42 MEZ Subject: Pointer-Allocation Message-Id: <52C767D10EA@merlin2.e-technik.uni-erlangen.de> Gruess Euch! I've written some programs with pointers and dynamic arrays, which might not be very exiting, but I came to a very interesting point, when using the realloc -function of libc.a. I defined a pointer int* p, malloc'ed and then realloc'ed some more space.(see source below) When using p[a]= a for initialising the pointerposition a , everything worked fine. I've never had an error. But when using *p=a; p=p+1; there was an error. (I did realloc the pointer before p+1 of course)- My super C- book (C-Grundlagen, Data Becker) told that this should cause no error. Somehow I had the idea to run it in a DOS Box (Win3.11) and there it works now (see source-code). My conclusion is, that this must be the DPMI server. My question: Which one behaves correctely? Or is a known thing which I' ve nerver heard of? Michi -------------------------------------------- /* Dyn.c Works fine in a DOS Box (Win 3.11) but doesnot work with native DOS */ #include #include int main(void) { int *p; int a; p=(int*) malloc(sizeof(int)); for (a=0;a<20;a++) { p=(int*) realloc(p,sizeof(int)*(a+1)); /* resizing p*/ *p=a; /* init the pointer */ printf(" Nummer: %d \t %d \n", a,*p); /* debug info */ /* The crucial statement */ if (!(p==NULL)) p=p+1; }; } ********************************************** Michael Schuster E-mail: Schuster AT eev DOT e-technik DOT uni-erlangen DOT de Universitaet Erlangen/Nuernberg Lehrstuhl fuer Elektrische Energieversorgung Cauerstrasse 4 91058 Erlangen http://www.eev.e-technik.uni-erlangen.de/ **********************************************