确切时间 [英] exact time

查看:76
本文介绍了确切时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

听起来微不足道(我希望是这样):我正在寻找一种获得

时间值的方法,而不仅仅是几秒钟(即我需要毫米或者几美元或类似的东西,至少和1/100秒一样好b / b
就足够了)它应该与gcc(真正的g ++)一起工作linux和

在Windows XP下符合MingW标准。


我在gmtime和& ;;中发现了一种简单而通用的声音方式。 co,但他们没有

似乎可以在我的windows mingw安装下使用。

是gmtime标准吗?我的mingw装置是否坏了?


如果它太过于无法找到*一个*的方式,那么我可能会对两个人感到高兴。 ifdef''代码块。


TIA

Henning

解决方案

Henning Hasemann< h。******** @ tu-bs.de>写道:

听起来微不足道(我希望是这样):我正在寻找一种方法来获得比单纯秒更准确的时间值(即我需要毫米或者/ >微秒或类似的东西,至少和1/100秒一样好就足够了)它应该与
linux下的gcc(真正的g ++)和windows xp下的MingW兼容。

我在gmtime和& ;;中找到了一种简单而通用的声音方式。 co,但是他们似乎没有在我的windows mingw安装下可用。
是gmtime标准吗?我的mingw装置是否破损了?

如果它太过于无法为两个操作系统找到* * *那么我会对两个#ifdef'代码块感到高兴,也是。




gmtime()是一个标准的C函数;你的mingw安装几乎

肯定支持它。它可能会遗漏一些其他非标准的

函数。


没有可移植的方式来获取任何特定的时间戳

决议; C标准甚至不保证1秒的分辨率

的时间()。


请参阅comp.lang.c FAQ中的问题19.37, < http://www.c-faq.com/> ;.


如需了解更多信息,请参阅系统文档。

使用和/或发布到系统特定的新闻组。


< OFF_TOPIC>< HINT> gettimeofday< / HINT>< / OFF_TOPIC>

-

Keith Thompson(The_Other_Keith) ks***@mib.org < ; http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


Henning Hasemann< h。******** @ tu-bs.de>写道:

听起来微不足道(我希望是这样):我正在寻找一种方法来获得比单纯秒更准确的时间值(即我需要毫米数)或者微秒或类似的东西,至少和1/100秒一样好
应该足够了)它应该在linux下使用gcc(真正的g ++)和在Windows XP下符合MingW标准。

我在gmtime& ;;中找到了一种简单而通用的声音方式。 co,但他们似乎没有在我的windows mingw安装下可用。
是gmtime标准吗?我的mingw装置坏了吗?




gmtime()是ISO C.如果你的MingW没有它,那它就坏了。 FWIW,我的

安装与MingW的Dev-C ++确实有它。但是,

gmtime()的ISO C部分不可能给你亚秒级的分辨率,因为

在struct tm中不是必需的成员,它创建的小于

整数秒(虽然允许添加额外的

成员,但那些是非标准的,因此是非便携的);

即使time_t也不能保证具有那么小的分辨率(尽管

当然是允许的);事实上,没有ISO C函数

确实给你这个。


Richard


Henning Hasemann写道:

大家好,
听起来微不足道(我希望是这样):我正在寻找一种方法来获得比单纯秒更精确的
时间值(即我需要毫秒或几微秒或类似的东西,至少和1/100秒一样好
应该足够)


标准C没有这样的机制。

它应该与gcc一起使用(实际上是g ++)


g ++是一个C ++编译器,*不是一个C编译器。 C ++是一种不同的语言

,它拥有自己的组。
Linux下的
和windows xp下的MingW兼容。

我在gmtime和& ;;中找到了一种简单而通用的声音方式。 co,但是他们不要


如果不是所有地方都不支持它几乎没有普遍性!

似乎可以在我的windows mingw安装下使用。
是gmtime标准吗?我的mingw装置是否破损?

如果它太过于无法为两个os找到* * *那么我会对两个#ifdef'代码块感到高兴,
要获得次秒级分辨率,你必须使用操作系统特定的机制

几乎可以肯定你将不得不使用条件编译。

-

Flash Gordon,生活在有趣的时代。

网站 - http://home.flash-gordon.me.uk/

comp.lang.c发布指南和介绍:
http://clc-wiki.net/wiki / Intro_to_clc


Hi all,
sounds trivial (I hope it is): Im searching for a way to get a
time-value thats more exact than just seconds (i.e. I need milli- or
microseconds or something similar, just at least as good as 1/100 second
should suffice) and it should work with gcc (really g++) under linux and
the MingW compliant under windows xp.

I found an easy and universal sounding way in gmtime & co, but they dont
seem to be available under my windows mingw installation.
Is gmtime standard? Is my mingw installation broken?

If it whould be too compilcated to find *one* way for both os'' I whould
be happy about two #ifdef''ed blocks of code, too.

TIA
Henning

解决方案

Henning Hasemann <h.********@tu-bs.de> writes:

sounds trivial (I hope it is): Im searching for a way to get a
time-value thats more exact than just seconds (i.e. I need milli- or
microseconds or something similar, just at least as good as 1/100
second should suffice) and it should work with gcc (really g++) under
linux and the MingW compliant under windows xp.

I found an easy and universal sounding way in gmtime & co, but they
dont seem to be available under my windows mingw installation.
Is gmtime standard? Is my mingw installation broken?

If it whould be too compilcated to find *one* way for both os'' I
whould be happy about two #ifdef''ed blocks of code, too.



gmtime() is a standard C function; your mingw installation almost
certainly supports it. It may be missing some other non-standard
functions.

There is no portable way to get a timestamp to any particular
resolution; the C standard doesn''t even guarantee 1-second resolution
for time().

See question 19.37 in the comp.lang.c FAQ, <http://www.c-faq.com/>.

For more information, consult the documentation for the systems you''re
using and/or post to a system-specific newsgroup.

<OFF_TOPIC><HINT>gettimeofday</HINT></OFF_TOPIC>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Henning Hasemann <h.********@tu-bs.de> wrote:

sounds trivial (I hope it is): Im searching for a way to get a
time-value thats more exact than just seconds (i.e. I need milli- or
microseconds or something similar, just at least as good as 1/100 second
should suffice) and it should work with gcc (really g++) under linux and
the MingW compliant under windows xp.

I found an easy and universal sounding way in gmtime & co, but they dont
seem to be available under my windows mingw installation.
Is gmtime standard? Is my mingw installation broken?



gmtime() is ISO C. If your MingW doesn''t have it, it''s broken. FWIW, my
installation Dev-C++ with MingW does have it. However, the ISO C part of
gmtime() cannot possibly give you sub-second resolution, because there
is no required member in the struct tm it creates smaller than an
integral number of seconds (though it is allowed to add additional
members, but those are then non-Standard and therefore non-portable);
even a time_t is not guaranteed to have that small a resolution (though
of course it''s allowed to); in fact, there is no ISO C function that
does give you this.

Richard


Henning Hasemann wrote:

Hi all,
sounds trivial (I hope it is): Im searching for a way to get a
time-value thats more exact than just seconds (i.e. I need milli- or
microseconds or something similar, just at least as good as 1/100 second
should suffice)
Standard C provides no such mechanism.
and it should work with gcc (really g++)
g++ is a C++ compiler, *not* a C compiler. C++ is a different language
with it''s own group.
under linux and
the MingW compliant under windows xp.

I found an easy and universal sounding way in gmtime & co, but they dont
It''s hardly universal if it isn''t supported everywhere!
seem to be available under my windows mingw installation.
Is gmtime standard? Is my mingw installation broken?

If it whould be too compilcated to find *one* way for both os'' I whould
be happy about two #ifdef''ed blocks of code, too.



To get sub second resolution you will have to use OS specific mechanisms
which almost certainly means you will have to use conditional compilation.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc


这篇关于确切时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆