Loading ...
Sorry, an error occurred while loading the content.

Re: [midatlanticretro] Stupid C question/Altair32

Expand Messages
  • Russell Frank
    My bad, you actually are right. I don t remember exactly who it was who told me that it s copied unless you pass a reference, but that s wrong - a[] and *a
    Message 1 of 15 , Dec 6, 2008
    • 0 Attachment
      My bad, you actually are right.  I don't remember exactly who it was who told me that it's copied unless you pass a reference, but that's wrong - a[] and *a are technically the same thing, but just because the compiler replaces it for you.

      However, since by typing a[] or a[8] or any length you're still just passing a reference (a pointer to the first element), it doesn't make any sense to write a[]; you might as well write the correct form *a.  This is evidenced by the fact that my other answer fixed the problem.

      see http://c-faq.com/aryptr/aryptrparam.html
      Russell Frank
      Burst Development


      Sridhar Ayengar wrote:

      M. Frank wrote:
      > You do realize that when you pass an array that way, using a[] as a
      > param in the definition of the function, that the entire array is copied
      > in memory, right? It's completely nonsensical to pass an uninitialized
      > array like that, you're essentially making a copy of uninitialized
      > memory, then using it, then freeing it. Might as well just malloc your
      > own work array in the function, or define the work array right there as
      > it'll be freed as soon as it goes out of scope.

      Arrays aren't passed by value in C though, right? So you'll just be
      passing a reference to an uninitialized memory location, not copying an
      uninitialized memory location.

      Peace... Sridhar

    Your message has been successfully submitted and would be delivered to recipients shortly.