在 2021-05-03 20:30, Christian Franke 写道:

Would plain '... = 0' without cast also work ? IIRC it should since C89 :-)
Alternative: Leave '/* = 0 */' only as a comment. There is no need to
set a static variable to 0.



Either using `= 0` as the initializer or omitting it should work. I don't 
prefer one to the other.

As for the `_Atomic` thing: Yeah it's C11, and I generally avoid its use (because it implies SEQ_CST order which is too strong). Here it is a pointer to the actual function to be called, and is initialized on demand, to something that is not going to change, so instead of writing

    ```c
    GetSystemTimeAsFileTime_t get_time = GetSystemTimeAsFileTime_p;
    if (get_time == NULL) {
      get_time = ... /* get the actual function */
      InterlockedCompareExchangePointer ((void * volatile *) 
&GetSystemTimeAsFileTime_p,
        get_time, NULL);
    }
    ```

, write

    ```c
    GetSystemTimeAsFileTime_t get_time = 
__atomic_load_n(&GetSystemTimeAsFileTime_p, __ATOMIC_RELAXED);
    if (get_time == NULL) {
      get_time = ... /* get the actual function */
      __atomic_store_n(&GetSystemTimeAsFileTime_p, get_time, __ATOMIC_RELAXED);
    }
    ```

which is semantically correct, and doesn't introduce any overhead. This works 
since GCC 7.

(If `get_time` pointed to mutable memory, instead of a pair of `__ATOMIC_RELAXED`, `__ATOMIC_CONSUME` and `__ATOMIC_RELEASE` would have to be used instead.)


--
Best regards,
Liu Hao

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to