standards

Declaring fixed-size integer typedef in Standard C

蹲街弑〆低调 提交于 2019-12-01 03:53:56
问题 Is there a reliable way to declare typedefs for integer types of fixed 8,16,32, and 64 bit length in ISO Standard C? When I say ISO Standard C, I mean that strictly: ISO C89/C90, not C99. No headers not defined in the ISO standard. No preprocessor symbols not defined in the ISO standard. No type-size assumptions not specified in the ISO standard. No proprietary vendor symbols. I see other questions similar to this in StackOverflow, but no answers yet that do not violate one of the above

C++ Standard: Unexpected const_iterator in multiset

。_饼干妹妹 提交于 2019-12-01 03:53:28
I recently ran into an odd issue where I'd get a const_iterator instead of the expected iterator when iterating through a multiset. It turned out to be a non-issue for MSVC but g++ gave me an error: error: invalid initialization of reference of type 'myPtr&' from expression of type 'const boost::shared_ptr' Relevant code: typedef std::multiset<myPtr> myList; myList _mystuff; void tick(float dt) { for (myList::iterator i = _mystuff.begin(); i != _mystuff.end(); ++i) { myPtr &mine = *i; // g++ problem here, not for MSVC // const myPtr &mine = *i; works fine for g++ mine->tick(dt); } } Quite a

Java label irregularity (possible bug?)

回眸只為那壹抹淺笑 提交于 2019-12-01 03:40:06
If we look at the Java standard §14.7, we see that statements may have label prefixes, e.g.: LabeledStatement:       Identifier : Statement In theory, a label should be able to label any succeeding statement. So, for example, the following compiles accordingly: public class Test { public static void main(String[] args) { hello: return; } } Intuitively, this also compiles: public class Test { int i; public static void main(String[] args) { Test t = new Test(); label: t.i = 2; } } But the following does not compile: public class Test { public static void main(String[] args) { oops: int k = 3; }

Correct behaviour of trivial statements involving expressions with volatile variables?

送分小仙女□ 提交于 2019-12-01 03:33:30
Consider the following statements volatile int a = 7; a; // statement A volatile int* b = &a; *b; // statement B volatile int& c = a; c; // statement C Now, I've been trying to find a point in the standard that tells me how a compiler is to behave when coming across these statements. All I could find is that A (and possibly C) gives me an lvalue, and so does B: "§ 5.1.1.8 Primary expressions - General" says An identifier is an id-expression provided it has been suitably declared (Clause 7). [..] [..] The result is the entity denoted by the identifier. The result is an lvalue if the entity is a

Why is a non-static data member reference not a variable?

折月煮酒 提交于 2019-12-01 03:21:31
The definition of a variable in C++11 is as follows (§3/6): A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name denotes the reference or object. So a non-static data member reference is not a variable. Why is this distinction necessary? What's the rationale here? Here's one way I can declare a variable in C++: int scientist = 7; After this declaration (and definition, in this case), I can use scientist to read and set its value, take its address, etc. Here's another kind of declaration:- class Cloud { public:

Is _ (single underscore) a valid C++ variable name?

扶醉桌前 提交于 2019-12-01 03:08:56
With gcc 4.7.2 this compiles just fine for me: int main() { int _ = 1; return 0; } Can I expect this to compile in general? I've read the answers about underscores as prefixes . But what if the underscore isn't prefixing anything? A name (identifier) consists of a sequence of letters and digits. The first character must be a letter. The underscore character, _, is considered a letter. From The C++ Programming Language, 4th Edition. According to Stroustrup (3rd edition, section 4.9.3), an identifier consists of a sequence of letters and digits. The first character must be a letter. The underscore

Which gcc and g++ version support which standard of c and c++?

微笑、不失礼 提交于 2019-12-01 02:30:55
For example, which gcc version support c99? Is there any table or graph to show the standard supported status of gcc and g++? How gcc and g++ evolved? Thank you~ Very strictly speaking, GCC only supports C89, C++98 and C++03, all for sure since 4.3. Support for C99 is still incomplete as of yet, but a very large and usable subset has been supported by GCC for a long time. Experiemental C++11 support started with 4.3 and has been improving ever since; it's already very usable in 4.6.x, and a lot more has been added in 4.7 (though 4.7.0 is a bit unstable). There is also some C11 support, but

strcmp() and signed / unsigned chars

徘徊边缘 提交于 2019-12-01 02:29:42
I am confused by strcmp(), or rather, how it is defined by the standard. Consider comparing two strings where one contains characters outside the ASCII-7 range (0-127). The C standard defines: int strcmp(const char *s1, const char *s2); The strcmp function compares the string pointed to by s1 to the string pointed to by s2. The strcmp function returns an integer greater than, equal to, or less than zero, accordingly as the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2. The parameters are char * . Not unsigned char * . There is no notion that

What is the longest possible email address? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-01 02:26:17
Possible Duplicate: Exceeding Max Email Address Sizes Is there a technical limitation to how long email addresses can be? Are there practical limitations imposed by the different major email providers out there (Google, Microsoft, etc.)? De jure or de facto, is there a limit on the number of characters in an email address? MasterCassim What is the maximum length of an email address? 254 characters "This arises from the simple arithmetic of maximum length of a domain (255 characters) + maximum length of a mailbox (64 characters) + the @ symbol = 320 characters. Wrong. This canard is actually

Why will std::rel_ops::operators be deprecated in C++20?

懵懂的女人 提交于 2019-12-01 02:25:26
According to cppreference.com , std::rel_ops::operator!=,>,<=,>= will be deprecated in C++20. What's the rationale behind? In C++20, you get three-way comparison (operator <=> ), which automatically "generates" default comparisons if provided: struct A { // You only need to implement a single operator. std::strong_ordering operator<=>(const A&) const; }; // Compiler generates all 6 relational operators A to1, to2; if (to1 == to2) { /* ... */ } // ok if (to1 <= to2) { /* ... */ } // ok, single call to <=> There are multiple advantages of the three-way comparison over std::rel_ops , which is