"David Buck" <da********@freeuk.com> writes:
If I have the following setup
void Vdlog_SetVport(int reason)
{
static double lx,ly,hx,hy;
Vmath_GetBox(&lx,&ly,&hx,&hy);
...
}
void Vmath_GetBox(double *lx,double *ly,double *hx,double *hy)
{
....
}
Will the pointers passed to Vmath_GetBox be out of scope (I have tried and
it causes a crash) ?
Ie are static variables only visible within the routine to which they are
declared ?
If you declare a static variable within a block, its name is visible
only within that block, but it has static storage duration, meaning
that it exists for the entire execution of the program. There should
be no problem with the code you posted. Even if the variables weren't
static, accessing them indirectly from a called function should be ok;
their lifetime doesn't end until Vdlog_SetVport() terminates, which
won't happen until *after* Vmath_GetBox() terminates. (In the latter
case, you could have problems if Vmath_GetBox() stashes away the
addresses of its parameters for use after Vdlog_SetVport() has
terminated, but even that's not a problem if the variables are static
-- though it would be horrible style.)
Is there a prototype for Vmath_GetBox() visible at the point of the
call? Even that probably shouldn't cause any visible problems, since
the types of the arguments match the expected types of the parameters,
unless your actual code differs from what you posted.
Can you trim your program to a small but complete program that
exhibits the problem?
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.