C (194/304)

From:Allan Odgaard
Date:20 Aug 2000 at 09:18:19
Subject:Re: Passing a ptr

On 19-Aug-00, Jack York wrote:

>> hmm... then the above looks even more wrong... please send the entire
>> function as an attachment, if you still want help with it...
> It's attached. [...]

Okay, the line in question should be changed
from: if ( ! ( *(array[i]) = ...
to: if ( ! ( (*array)[i] = ...

Using a temporary variable may help the readability -- but as you may
have realized then it's generally a very bad idea to pass pointers to
functions which are then assumed to fill these pointers, because it a)
adds extra syntax which can easily go wrong and b) the code gets more
complicated, i.e. saying "array = MakeArray()" tells you that the
variable is initialized (and the compiler will complain if either
MakeArray() is declared to return the wrong type, or if the function
forgets to return it), but "MakeArray(&array)" doesn't need to do
anything, and the compiler won't complain...