On Mon, Mar 14, 2011 at 12:31, Jakub Jelinek <ja...@redhat.com> wrote:
> On Mon, Mar 14, 2011 at 12:18:16PM +0200, Janne Blomqvist wrote:
>> On Sat, Mar 12, 2011 at 17:21, FX <fxcoud...@gmail.com> wrote:
>> A static variable which is modified introduces a race condition.
>
> That is true.
>
>> Secondly, you reset the count to 0 at the start of every loop which
>> makes the static thing superfluous?
>
> This is wrong, in C, C++
> static int count = 0;
> means that the static variable is initialized to 0 in its static storage,
> not that count = 0; is executed anywhere where the static block local
> variable enters its scope.

Oops, brown paper bag moment. :)

I remembered that this was a case where C and Fortran differ, but
alas, both work similarly.

>  The "= 0" part is redundant for static vars
> BTW, static vars are initialized to 0 when they don't have an explicit
> initializer.

Well, FWIW, this is where C and Fortran differ, as Fortran static vars
(SAVE) have undefined initial value unless explicitly initialized. In
practice, gfortran puts them into .bss so they are zero initialized,
but from the perspective of the standard their value is undefined.

> If M$ mktemp when already 26 files exist with the same prefix at least
> properly fails, then it would be better to just retry with a changed prefix
> if it fails.

Yes, this was what I meant with my proposal to make count an automatic
instead of static and initializing it outside the do-while loop.


-- 
Janne Blomqvist

Reply via email to