Path: utzoo!attcan!uunet!samsung!spool.mu.edu!uwm.edu!rpi!crdgw1!camelback!volpe From: volpe@camelback.crd.ge.com (Christopher R Volpe) Newsgroups: comp.lang.c Subject: Re: calloc and realloc semantics Keywords: calloc realloc Message-ID: <16436@crdgw1.crd.ge.com> Date: 5 Feb 91 13:59:09 GMT References: <4865@cui.unige.ch> Sender: news@crdgw1.crd.ge.com Reply-To: volpe@camelback.crd.ge.com (Christopher R Volpe) Lines: 45 In article <4865@cui.unige.ch>, afzal@cui.unige.ch (Afzal Ballim) writes: |>. |>X *array1, array2; ^^^^^^^^ I think you mean *array2 |>. |>/* n is the size we begin with */ |>array1 = (X *) calloc(n,sizeof(X)); |>. |>/* m is the new size that we want */ |>array2 = (X *) realloc(array1,m*sizeof(X)); |>. |> |>After the realloc, what is the status of array1? The value of the variable "array1" is unchanged, but the storage it points to is not necessarily valid. |> Does it still point to the |>originally sized array? That array no longer exists. |>Even if the block has been "moved" as the |>documentation (of Sun's C) says may happen? |> |>Is this use of newsize*sizeof(element) valid? I am worried here about |>alignment of elements. That's fine. All three routines (calloc, malloc, realloc) are guaranteed to satisfy the strictest alignment requirement on the machine. |>---------------------------------------------------------------------- --------- |>Afzal Ballim |EAN,BITNET,EARN,MHS,X.400: afzal@divsun.unige.ch |> ISSCO, University of Geneva |UUCP: mcvax!cernvax!cui!divsun.unige.ch!afzal |> 54 route des Acacias |JANET: afzal%divsun.unige.ch@uk.ac.ean-relay |> CH-1227 GENEVA,Switzerland |CSNET,ARPA: afzal%divsun.unige.ch@relay.cs.net ================== Chris Volpe G.E. Corporate R&D volpecr@crd.ge.com