Peter Kirk wrote:[color=blue]
>
> Hi there
>
> I have a question about static variables. There is a function which returns
> a pointer to a structure "AStructure". The function has a static local
> variable of type AStructure, and it is the address of this variable which is
> returned. Is this good practice?
>
> See this pseudo code:
>
> AStructure *my_function()
> {
> static AStructure result;
>
> // "result" is filled with data...
>
> return ( &result );
> }[/color]
With the caveat that each call to my_function() overwrites the result
of the previous call, there is nothing "wrong" with the above code.
Because the local variable is static, it still exists upon return from
the function, and "&result" is still a valid pointer.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody |
www.hvcomputer.com | |
| kenbrody at spamcop.net |
www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+