LIU Hao wrote:
在 2023/7/16 00:59, Christian Franke 写道:
According to https://en.cppreference.com/w/c/chrono/localtime C11
added optional gmtime_s() and localtime_s() which conflict with the
long standing MSVCRT/UCRT variants. I have no idea why they did this
(C23 finally adds the traditional *_r() functions which are IIRC
older than POSIX).
I have some questions about this request:
1) This patch seems to propose overloaded `localtime_s()` in C++. However
wouldn't they conflict because `extern "C"` functions can't be
overloaded?
This code is outside the 'extern "C" {...}' block. This fact is somewhat
hidden in the first 2 lines of the patch :-)
I also verified the generated assembly code from C++ testcases.
2) How many projects are there which expect those Annex K functions?
There are some implementations of Annex K at github, but I'm don't know
any project actually using these.
I learned about the incompatible versions of these functions because
cppcheck developers decided to add the C11 variants unconditionally:
https://trac.cppcheck.net/ticket/11826
AFAICT
when targeting Linux or BSD people generally expect the POSIX one, and
for Windows they expect the Microsoft one; in neither world has the
C11
one gained wide acknowledgement. UCRT is only officially documented as
C99 [1] with some C11 extensions e.g. `_Alignas` and 'stdalign.h';
some
parts are missing or non-conforming.
Yes, as usual MS C libs add standard items never or very late, e.g. long
long, stdint.h, inttypes.h, ...
3) The macro `__STDC_LIB_EXT1__` doesn't seem to belong in 'time.h'.
Ideally there should be a general macro in '_mingw.h'; then here
arises
another question: Should we add Annex K functions as how it is
proposed
now: adding stuff piece by piece, expecting other people to test it in
their projects which seems quite unlikely to me, and assuming it's
free
of bugs because nobody has reported any? That doesn't sound good.
AFAICS various of the Annex K *_s() functions are long standing parts of
MSVCRT/UCRT and have a compatible signature.
The patch was not intended to be a starting point for adding any of the
missing functions. It only should fix this incompatibility if requested.
Therefore, an alternative would be to use something like
__MINGW_STDC_WANT_LIB_EXT1__ instead of __STDC_WANT_LIB_EXT1__ to
control what function variants are visible.
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public