English 中文(简体)
2. 时间上限——与视觉演播室挂钩
原标题:Get maximum value for time_t with Visual Studio

我需要独立的以下守则工作平台:

 timeval tv;
 tv.tv_sec = std::numeric_limits<time_t>::max();

该法典在各种类型的欧诺托公司和MacOS X公司下进行罚款。

不幸的是,在窗户下,这将会恢复-1,就象牙那样。

我当时想到的是重新确定时间。

 typedef int time_t;

这并不是因为 com子现在抱怨:

error C2371:  time_t  : redefinition; different basic types

我怎样才能使该法典独立运行?

最佳回答
tv.tv_sec = std::numeric_limits<decltype(tv.tv_sec)>::max();

不含cl类的替代品

template<typename T> 
void set_max(T& val){val = std::numeric_limits<T>::max();}

set_max(tv.tv_sec);
问题回答

<>你不能这样做。 时间――t isn t 甚至必然是整体类型。 这可能是一种障碍或实际上的任何东西。

既然你想重新确定谁是谁是谁是谁,那么你为什么不在那里使用正确的类型? 这被定义为长期,因此,你应当:

tv.tv_sec = std::numeric_limits<long int>::max();

Although, I notice now that POSIX says tv_sec is a time_t even though MSDN and the GNU libc use long int. These old time APIs that can t even distinguish between durations and time points are definitely due for replacement. If you can use C++11 check out std::chrono.

任何途径,std: 识数_limits<std:time_t>:max( 事实上,甚至视窗都给予最大时间——t值。 问题只是“温得”的定义: tv_sec isn t time_t as POSIX mandate, and so the put to long int have the anti number.

However this can be fixed on Windows by defining _USE_32BIT_TIME_T. This will cause the definition for time_t to match the type used in timeval for tv_sec, and then your std::numeric_limits<time_t>::max() will work.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签