Welcome, Guest. Please login or register.

Author Topic: Learning C with the Amiga  (Read 32470 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Hans_

Re: Learning C with the Amiga
« on: February 07, 2007, 08:45:53 PM »
@mel_zoom

With regard to Q3, the only reason I can think of, for passing structures by value to a function would be if the function required a local copy of the data. That would be the case if the function had to modify the data during processing but wasn't allowed to modify the original copy belonging to whatever code called that function.

I have never had to pass a structure by value, ever. Doing so will just slow the program down, particularly if it's a big structure (e.g., contains a large fixed-size array) or that function gets called really often.

Hans
Join the Kea Campus - upgrade your skills; support my work; enjoy the Amiga corner.
https://keasigmadelta.com/ - see more of my work
 

Offline Hans_

Re: Learning C with the Amiga
« Reply #1 on: February 07, 2007, 09:30:02 PM »
Quote

mel_zoom wrote:
hans:

I understand that and I can see why arrays are "by reference" but why are structures allowed to be by value? Especially as they can contain an array even?


Because a structure is seen as a data-type whereas an array is not. An array is a method of addressing a set of data of the same type. It's a quirk of the language.

BTW, I think that lou_dias is wrong about arrays in structures. A fixed-length array in a structure is the data itself, not a pointer to the array. Ah, I see that Karlos has already commented on that as I was writing this.

Hans
 
Join the Kea Campus - upgrade your skills; support my work; enjoy the Amiga corner.
https://keasigmadelta.com/ - see more of my work