rlb@hoekstra-uitgeverij.nl (Richard Bos) writes:
> Peter Pichler <usenet@pichler.co.uk> wrote:
>
>> Ed Jensen wrote:
>>
>> > done:
>> > if (sf)
>> > fclose(sf);
>> > if (df)
>> > fclose(df);
>>
>> As you wish. I do not like this approach because it requires all
>> declarations at the top of the function, which IMO is almost as bad
>> as making them global.
>
> Beg to differ. Beg to differ very greatly, in fact. Declarations
> scattered through the code hailshot-wise are a great way of ensuring
> that you'll have to hunt for one sooner or later.
Not with any half decent editor. Besides, locally declared variables
don't need to be hunted for. They are there where you need
them. Declaring all variables in one go at the top is bad for
maintenance and leads to confusion IMO. Declare the variable at the last
possible moment. It also keeps the locals display in your debugger
cleaner and only showing what is pertinent to the current context.
>
>> In addition, it requires them initialised to "harmless" values
>> which can hide bugs later on.
>
> No, it doesn't. For example, in the code from which the above is quoted,
> the initialisations of sf and df are unnecessary: fopen() will always
> return either a valid FILE *, or a null pointer, never garbage.
>
> Richard