[comp.lang.c] Getting arrays and structs into and out of functions,...

rburgess@milton.u.washington.edu (Rick Burgess) (04/18/91)

I think I need to clarify my question.  I am, as yet, a novice so please
realize I need the simple and the complex answers.  I wish to get structs
and arrays into and out of my functions in ways which are appropriately
clear, regular/normal/standard, efficient, and hopefully even orthoganal.

tlglenn@cs.arizona.edu (Ted L. Glenn) (04/18/91)

In article <1991Apr17.212135.5922@milton.u.washington.edu>, Rick Burgess writes
> I think I need to clarify my question.  I am, as yet, a novice so please
> realize I need the simple and the complex answers.  I wish to get structs
> and arrays into and out of my functions in ways which are appropriately
> clear, regular/normal/standard, efficient, and hopefully even orthoganal.


     C will pass the address of the first element of the array to the function,
which will be expecting an address. So, in general you can:

         call_f(array[10]) <-- I wonder if the 10 is really required here...
                                 but it works for me on Turbo C.

         void call_f(array[]) <--Notice no 10. The function is only expecting
the address of the beginning of the array. You can still do array[0]++ or
something, but be careful not to reference the array outside of it's
initially declared bounds (remember, an array of 10 goes from 0 to 9!).

-- 
        -Ted L. Glenn             "Don't worry, be happy!" <--Ack! Pffffhhht!
         tlglenn@cs.arizona.edu        tlglenn@hacks.arizona.edu
         G19382105@ccit.arizona.edu    G19382105@ARIZRVAX.BITNET