时间函数在mingw中 [英] Time functions in mingw
问题描述
我试图执行本页中给出的代码
http://msdn.microsoft.com/en-us/library/windows/desktop/aa366062%28v=vs.85% 29.aspx
我使用mingw(gcc)来编译这个。
但是下面的行不能被编译。我已经包含'time.h'。我搜索了,但无法在gcc中找到'_localtime31_s'或其等价物。
error = _localtime32_s(&newtime,(__time32_t * )& pAdapter-> LeaseObtained);
error = asctime_s(buffer,32,& newtime);
这里的时间函数在哪里?
谢谢
localtime_s
和 asctime_s
是Microsoft特定的扩展,由MS运行时库(的某些版本)提供。这由MS头文件提供。由于这些版权为MS并且不允许免费发布,所以mingw提供它自己的版本 - 这些扩展名可能不包含这些扩展名(当我在本地机器上使用mingw时,他们肯定不会回来 - 我的主要机器这些天运行Linux ...)。 请注意,将时间值转换为 time32_t *
可能是一个坏主意 - 几乎肯定会咬人如果你用
< href =http://pubs.opengroup.org/onlinepubs/009695299/functions/localtime.html =nofollow> localtime_r
功能是一个可以用来代替 localtime_s
的半标准版本(你需要注意32位和64位时间值)。你当然也可以使用 localtime
(除了必须关闭MS烦人的功能外此功能不安全,请使用 ... ... s
改为 - 我真的不想 em 将我使用strcpy的100次转换为strcpy_s,因为它已经在别处检查过了,所以它工作得很好。
同样, asctime_r
,它提供了一个可重入版本。
也许你也可以将这些函数的原型添加到你的文件中,我相信只要你为Windows编译,就可以解决这个问题:
链接到MS函数文档: localtime_s
和
I am trying to implement the code given in this page
http://msdn.microsoft.com/en-us/library/windows/desktop/aa366062%28v=vs.85%29.aspx
I am using mingw (gcc) to compile this. But the following lines cannot be compiled. I have included 'time.h'. I searched but cannot locate this '_localtime31_s' or its equivalent in gcc.
error = _localtime32_s(&newtime, (__time32_t*) &pAdapter->LeaseObtained);
error = asctime_s(buffer, 32, &newtime);
Where is the time functions here? Thanks
The functions localtime_s
and asctime_s
are Microsoft-specific extensions, provided by (certain versions of) the MS runtime library. This is provided by the MS header files. Since those are copyright MS and not allowed for free distribution, mingw provides its own versions of headers - and these probably don't contain these extensions (they certainly didn't a while back when I was using mingw on my local machine - my main machine these days runs Linux...).
Note that casting the time value to time32_t *
is probably a bad idea - it is almost certainly going to bite you if you ever compile your code with a time_t
that isn't a 32-bit value.
The localtime_r
function is a semi-standard version that could be used instead of localtime_s
(you will need to pay attention to 32 vs 64-bit time values). You can certainly also use localtime
(aside from having to turn off MS's annoying "this function is not safe, please use ..._s
instead" - I don't REALLY want to convert my 100 uses of strcpy to strcpy_s that work perfectly fine because it has already been checked elsewhere).
Similarly there is asctime_r
which provides a re-entrant version.
You could, perhaps, also add the prototypes for these functions to your file somewhere, I believe that would, as long as you are compiling for Windows, solve the problem:
Link to MS function documentation: localtime_s
and asctime_s
.
这篇关于时间函数在mingw中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!