LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   regarding structures (https://www.linuxquestions.org/questions/programming-9/regarding-structures-316906/)

eshwar_ind 04-25-2005 05:34 AM

regarding structures
 
Hi,
Could anyone explain me, how the structures are passed to functions by call by value method? Does compiler copy the full structure in to the stack frame of the called function( i.e compiler generates the code in such a way that stack frame has got enough space to hold the structure, & some stub to copy the structure into that frame at runtime. ) or is there any other method? . please reply me.
thanks & regards
Eeshwar.

jtshaw 04-25-2005 06:59 AM

If you pass a static structure then I'm pretty sure it does get dumped entirely on the stack. The only real alternative to this is to not pass a static structure... pass a reference to it so your function can access it in the heap.

If for some reason your trying to save stack space (like if your programming in the kernel for instance) but you still want the function to get it's own copy then you'll have to make a copy of the structure and then pass the copy by reference. Typically, in the kernel anyway, we don't worry about this and we just pass the original by reference and make sure we don't change anything we shouldn't be changing...

eshwar_ind 04-25-2005 09:18 AM

Thanks Jtshaw.


All times are GMT -5. The time now is 08:19 AM.