Re: Function and variable declarations
- From: "Joseph Wakeling" <joseph.wakeling@xxxxxxxxx>
- Date: 27 Nov 2005 01:23:42 -0800
Thanks to all for helpful answers about this!
Flash Gordon wrote:
> Global (or at least file scope) variable named x and n? Yuk.
Normally I would agree. Originally these variable came as part of a
structure called "state", so the system was referring to state->x,
state->n and state->shuffle. Given the content of the program and how
it's going to be used (as an individually compiled module) it's not a
big deal.
> > return;
>
> Rather pointless having a return here IMHO.
That came with the GSL and I left it in. return; at the end of a void
function is a matter of preference anyway, right? It doesn't
functionally affect things but some people prefer it for readability.
> It's called minimising scope. Because they are declared in the loop you
> know, without having to check, that they are not used outside.
> Otherwise, you would have to read beyond the end of the loop to see if
> the last value gets used outside the loop.
OK. Does it make any difference to the speed at which the code runs?
Let's assume I'm going to be calling this function a LOT so small
differences add up. :-)
Many thanks again for this & all other useful advice.
-- Joe
.
- Follow-Ups:
- Re: Function and variable declarations
- From: Flash Gordon
- Re: Function and variable declarations
- References:
- Function and variable declarations
- From: Joseph Wakeling
- Re: Function and variable declarations
- From: Flash Gordon
- Function and variable declarations
- Prev by Date: Re: New Logic
- Next by Date: Re: Function and variable declarations
- Previous by thread: Re: Function and variable declarations
- Next by thread: Re: Function and variable declarations
- Index(es):