From: Mark van der Aalst Newsgroups: comp.os.msdos.djgpp Subject: Re: question on structures Date: 11 Jul 1998 03:52:18 +0200 Organization: Eindhoven University of Technology, The Netherlands Lines: 43 Sender: flux AT toad DOT stack DOT nl Message-ID: <6o6ggi$hc5$1@toad.stack.nl> References: <6o63dl$ojc$1 AT ash DOT prod DOT itd DOT earthlink DOT net> NNTP-Posting-Host: toad.stack.nl User-Agent: tin/pre-1.4-980202 (UNIX) (FreeBSD/2.2.6-STABLE (i386)) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Jason Nehf wrote: > How would I pass a structure in a function, then have the function change > the values in the structure? I know with regular variables, you just pass > them by putting a '&' in front of the variable, but is there an equivilant > with structures? Specifically, I'm trying to pass a structure with all of a > RPG character's attributes (hitpoints, strength, dexterity, etc), and have > it accelerate the character to a specific level. I know i could, instead of > passing a structure, pass each variable individually, but that is a LOT of > work that could be saved by passing a structure. Any help would be greatly > appreciated! You can pass stuctures either by value or reference, most programmers perfer by reference since it's generally faster (other wise the whole structure needs to be put on the stack) so ; typedef struct { int zop; float bar; } foo_t ; /* by value */ foo_t my_func(foo_t foo) { foo.zop = 12; foo.bar = 0.24; return foo ; } or /* by reference */ foo_t * my_func(foo_t * foo) { foo -> zop = 12; foo -> bar = 0.24; return foo ; } Cheers, flux.