Re: C question





 > void some_function (...) {
 >    item temp;
 > 
 >    temp.text = "Some text that the user defines and changes from time to
 > time";
 >    add_item(temp);
              ^^^^^^

You might want to avoid this.  If 'item' is a simple as in this
example it doesn't matter that much, but if it is larger this can be
expensive

>From the C FAQ:

==========================================================================
Question 2.9

How are structure passing and returning implemented? 

--------------------------------------------------------------------------

When structures are passed as arguments to functions, the entire
structure is typically pushed on the stack, using as many words as are
required. (Programmers often choose to use pointers to structures
instead, precisely to avoid this overhead.) Some compilers merely pass
a pointer to the structure, though they may have to make a local copy
to preserve pass-by-value semantics.

Structures are often returned from functions in a location pointed to
by an extra, compiler-supplied ``hidden'' argument to the
function. Some older compilers used a special, static location for
structure returns, although this made structure-valued functions
non-reentrant, which ANSI C disallows.

References: ANSI Sec. 2.2.3 
ISO Sec. 5.2.3 

==========================================================================

Anyway, in this case you don't need the actual structure, just the
pointer, so just use

      add_item(&temp);

        /mailund




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]