LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2005, 05:34 AM   #1
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Rep: Reputation: 15
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.
 
Old 04-25-2005, 06:59 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
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...
 
Old 04-25-2005, 09:18 AM   #3
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Original Poster
Rep: Reputation: 15
Thanks Jtshaw.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing structures to function b123coder Programming 3 04-20-2005 10:15 AM
initializing arrays of structures in c dreamgoat Programming 5 09-27-2004 02:02 AM
Structures AMMullan Programming 6 02-18-2004 11:39 AM
Nested structures :S? alitrix Programming 11 11-15-2003 07:13 PM
C and arrayed structures.. miguetoo Programming 9 05-22-2003 06:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration