standards

Convert double to time_t

筅森魡賤 提交于 2019-12-06 00:00:31
问题 I have a double containing seconds. I would like to convert this into a time_t . I can't find a standard function which accomplishes this. Do I have to fill out the time_t by hand? 回答1: The type of std::time_t is unspecified. Although not defined, this is almost always an integral value holding the number of seconds (not counting leap seconds) since 00:00, Jan 1 1970 UTC, corresponding to POSIX time. So, just a safe casting between them could be fine. Also be carefull about portability

Why is there no language support in C++ for all C++ standard library type traits?

青春壹個敷衍的年華 提交于 2019-12-05 23:15:20
In C++ it is impossible to implement certain C++ standard library type traits without compiler intrinsics, using the C++ language only. Traits deal directly with C++ types. According to §17.6.1.3.2 freestanding implementations of the C++ standard library must implement <type_traits> . Doesn't this effectively mean that the C++ standard requires non-standard language extensions/compiler intrinsics from all compilers which support want to support freestanding C++ standard library implementations? Why were such type traits allowed into the standard without support in the core language? There are

What type will make “std::has_unique_object_representations” return false?

若如初见. 提交于 2019-12-05 21:46:08
问题 At cppref, I see a weird type trait checker : std::has_unique_object_representations From its description, I cannot imagine any type T that make std::has_unique_object_representations<T>::value is false . Is there any counter-example? 回答1: Understanding the purpose of this trait requires understanding the distinction between an objects "value representation" and its "object representation". From the standard: The object representation of an object of type T is the sequence of N unsigned char

PHP Constants: Advantages/Disadvantages

℡╲_俬逩灬. 提交于 2019-12-05 21:01:20
问题 Lately I've been in the habit of assigning integer values to constants and simply using the constant name as a means of identifying its purpose. However, in some cases this has resulted in the need to write a function like typeToString($const) when a string representation is needed. Obviously this is inefficient and unneccesary, but is only an issue every once and a while. So my question is, are there any other tradeoffs I should consider? Which case is considered to be cleaner/more standards

Alignment of char array struct members in C standard

假如想象 提交于 2019-12-05 20:52:23
Let us suppose I would like to read/write a tar file header. Considering standard C (C89, C99, or C11), do char arrays have any special treatment in structs, regarding padding? Can the compiler add padding to such a struct: struct header { char name[100]; char mode[8]; char uid[8]; char gid[8]; char size[12]; char mtime[12]; char chksum[8]; char typeflag; char linkname[100]; char tail[255]; }; I've seen it used in code on the web as well. Just freading, fwriting this struct to the file in one chunk, assuming there will not be any padding. Of course also assuming CHAR_BITS == 8 . I'm thinking

C string append

眉间皱痕 提交于 2019-12-05 20:05:37
I've got two C strings that I want to append and result should be assigned to an lhs variable. I saw a static initialization code like: char* out = "May God" "Bless You"; . The output was really "May GodBless You" on printing out. I understand this result can be output of some undefined behaviour. The code was actually in production and never gave wrong results. And it was not like we had such statements only at one place. It could be seen at multiple places of very much stable code and were used to form sql queries. Does C standard allow such concatenation? Yes, it is guaranteed. Extract from

How to successfully use RDAP protocol instead of whois

橙三吉。 提交于 2019-12-05 19:58:13
I'm a little confused about the new RDAP protocol and whenever it makes sense to pursue it any further. It looks to me like everyone agreed on it to be the successor of whois, but their databases seem empty. On ubuntu I tried rdapper, nicinfo and even their RESTful API: http://rdap.org/domain/google.com (this results in a "File not Found", but is correct according to here ) Am I misunderstanding something? Is RDAP dead, did the service not start yet or am I doing something wrong? Nicinfo returns this: nicinfo -t domain google.com # NicInfo v.1.1.0-alpha # Query yielded no results. [ NOTICE ]

Appropropriate URN namespace now that X- is deprecated?

穿精又带淫゛_ 提交于 2019-12-05 18:23:54
As recently as 2002 the IETF was recommending in RFC 3406 that we should use x- prefixes for URN namespaces we didn't want to register, e.g. urn:x-acme:foobar . Now that the IETF has deprecated the x- prefix in RFC 6648 , how are we supposed to construct URNs for namespaces we don't intend to register? As an aside, I note that RFC 6648 specifically mentions URNs: "In almost all application protocols that make use of protocol parameters (including ... URNs ...), the name space is not limited or constrained in any way, so there is no need to assign a block of names for private use or

Why does the default setting for `requestPathInvalidCharacters` exclude otherwise-allowed characters?

天大地大妈咪最大 提交于 2019-12-05 16:50:53
问题 In ASP.NET, the httpRuntime/@requestPathInvalidCharacters attribute defaults to <,>,*,%,&,:,\ . These characters, as I understand, are disallowed in the path portion of a URL (based on the default setting of this attribute), but some of them should be allowed. Out of that list, I struggle to understand why *,&,: are disallowed by default. E.g., the following URLs are valid but would be rejected by default by ASP.NET: To get a unique person by email: http://myservice.com/People/Email=jim@smith

C# IComparer<T> standard usage question

假装没事ソ 提交于 2019-12-05 16:42:58
I have a question with whether or not this is a standard for using IComparer in C#. Say I have a situation in which there are three Person objects: P1, P2, and P3. Say I call the Compare method passing in P1 and P2 and the result is 0. This essentially means the two people should be categorized as equal. Now say I call the Compare method passing in P2 and P3 and the result for that is 0 as well. Again, this means the two people are equal. Logically speaking, one can assume P1 and P3 are equal as well; however, the Compare method could be implemented however someone decides to implement it. So