Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!sdd.hp.com!caen!sol.ctr.columbia.edu!emory!gatech!purdue!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: calloc and realloc semantics Keywords: calloc realloc Message-ID: <15084@smoke.brl.mil> Date: 5 Feb 91 19:50:57 GMT References: <4865@cui.unige.ch> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 20 In article <4865@cui.unige.ch> afzal@cui.unige.ch (Afzal Ballim) writes: >Is it safe (and portable) to use realloc to resize an array that >was generated using calloc? calloc() is supposed to be simply an interface to malloc() that also fills the allocated storage with 0-valued bytes. Thus it isn't very useful, but it should be safe to use in conjunction with other functions in the malloc() family. >... After the realloc, what is the status of array1? If array2 is a null pointer, then array1 should still points to the same data (and same-sized allocation) as before; otherwise, array1 is now an invalid pointer and should not be further used. In the latter case, you must use array2 to access the (possibly moved) data. >Is this use of newsize*sizeof(element) valid? I am worried here about >alignment of elements. Yes, there is no problem with that.