ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2011/06/04/09:15:23

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Mok-Kong Shen <mok-kong DOT shen AT t-online DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Different memory allocations were to the same location
Date: Sat, 04 Jun 2011 15:02:58 +0200
Organization: albasani.net
Lines: 27
Message-ID: <isdadm$amb$1@news.albasani.net>
Mime-Version: 1.0
X-Trace: news.albasani.net s/c66Q5O/x+TrbP1+6MU4knCkVCcKbl+j34OEA5Nqxa18ooIa9V7u44U8Tmn+GoJAk/XfV/8wr1S6or2sH7Gew==
NNTP-Posting-Date: Sat, 4 Jun 2011 13:02:46 +0000 (UTC)
Injection-Info: news.albasani.net; logging-data="sxngdiGPxacUehdSKzt3RMpkfDL8wJgHDAyEylZC69GT2QFuMyXgj8wHWNm01KMZYWk+33LjKALSLtFhrNWvJ/2ul2hcgNrntIi1IF/rqQ2osncjwqY/MOy3iUZhLLb+"; mail-complaints-to="abuse AT albasani DOT net"
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
Cancel-Lock: sha1:v3KCueuHiPghLVAL7wh8gRQwNzM=
Bytes: 1846
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I wrote a function to allocate memory to arrays of integers. But
it turns out that the the momory allocated was always at the same
location. What had I done improperly and how could I get around
the problem? (I use version 2 of the compiler.)

Thanks in advance.

M. K. Shen
-------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>

void generateintvec(int *uh, int len)
{ free(uh);
   uh=calloc(len,sizeof(int));
   if (uh==NULL) printf("memmory allocation unsuccessful !!!\n");
}

int *vec1, *vec2;

int main()
{ generateintvec(vec1,30);
   generateintvec(vec2,30);
   if (vec1==vec2) printf("allocations were to the same location !!!\n");
   return(0);
}

- Raw text -


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