standards-compliance

Is `auto int i` valid C++0x?

匆匆过客 提交于 2019-12-01 08:22:26
In answering this question the question arose as to whether the traditional C meaning of the keyword auto (automatic storage) is still valid in C++0x now that it means type deduction. I remember that the old meaning of auto should remain where relevant but others disagreed. auto char c = 42; // either compilation error or c = '*' Looking at compilers I see the current division. Old meaning of auto is no longer allowed VS10 g++ Old meaning of auto is used where relevant Comeau Do you know which is the correct behaviour? No, it is not. In fact, §7.1.6.​4/3 gives the following example: auto x = 5

Is `auto int i` valid C++0x?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 07:12:11
问题 In answering this question the question arose as to whether the traditional C meaning of the keyword auto (automatic storage) is still valid in C++0x now that it means type deduction. I remember that the old meaning of auto should remain where relevant but others disagreed. auto char c = 42; // either compilation error or c = '*' Looking at compilers I see the current division. Old meaning of auto is no longer allowed VS10 g++ Old meaning of auto is used where relevant Comeau Do you know

multipart/form-data, what is the default charset for fields?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 03:09:46
what is the default encoding one should use to decode multipart/form-data if no charset is given? RFC2388 states: 4.5 Charset of text in form data Each part of a multipart/form-data is supposed to have a content- type. In the case where a field element is text, the charset parameter for the text indicates the character encoding used. For example, a form with a text field in which a user typed 'Joe owes <eu>100' where <eu> is the Euro symbol might have form data returned as: --AaB03x content-disposition: form-data; name="field1" content-type: text/plain;charset=windows-1250 content-transfer

What's the difference between “dead code” and “unreachable code”?

断了今生、忘了曾经 提交于 2019-11-30 17:32:20
I thought those terms where synonymous, but a note in MISRA regarding dead code indicates this to be wrong? What's the difference? Is one a subset of the other? Dead code - code that is executed but redundant, either the results were never used or adds nothing to the rest of the program. Wastes CPU performance. function(){ // dead code since it's calculated but not saved or used anywhere a + b; } Unreachable code - code that will never be reached regardless of logic flow. Difference is it's not executed. function(){ return x; // unreachable since returned a = b + c; } Dead Code Code that

Should I learn XML 1.0 or XML 1.1?

我们两清 提交于 2019-11-30 12:35:21
问题 I know that a well-formed XML 1.1 is not necessarily a well-formed XML 1.0 and vice-versa. I want to learn xml formally and i was wondering whether i should learn XML 1.0 or XML 1.1? I mean would it be more effective to learn XML 1.0 or would it be more effective to learn XML 1.1? I mean of course I know its best to read them both.. but i really only have the time to read one of them, so which would be "better" (more useful to me, me as in the average programmer)? 回答1: Unless you have a

Should I learn XML 1.0 or XML 1.1?

回眸只為那壹抹淺笑 提交于 2019-11-30 03:02:57
I know that a well-formed XML 1.1 is not necessarily a well-formed XML 1.0 and vice-versa. I want to learn xml formally and i was wondering whether i should learn XML 1.0 or XML 1.1? I mean would it be more effective to learn XML 1.0 or would it be more effective to learn XML 1.1? I mean of course I know its best to read them both.. but i really only have the time to read one of them, so which would be "better" (more useful to me, me as in the average programmer)? alexbrn Unless you have a specific requirement to work with XML 1.1 (which is very rare), you should read the XML 1.0

May pointer to members circumvent the access level of a member?

北慕城南 提交于 2019-11-30 02:05:09
Our infamous litb has an interesting article on how to circumvent the access check . It is fully demonstrated by this simple code: #include <iostream> template<typename Tag, typename Tag::type M> struct Rob { friend typename Tag::type get(Tag) { return M; } }; // use struct A { A(int a):a(a) { } private: int a; }; // tag used to access A::a struct A_f { typedef int A::*type; friend type get(A_f); }; template struct Rob<A_f, &A::a>; int main() { A a(42); std::cout << "proof: " << a.*get(A_f()) << std::endl; } Which compiles and runs (output 42 ) with gcc 4.3.4 , gcc 4.5.1 , gcc 4.7.0 (see

What's the difference between “dead code” and “unreachable code”?

岁酱吖の 提交于 2019-11-30 01:13:25
问题 I thought those terms where synonymous, but a note in MISRA regarding dead code indicates this to be wrong? What's the difference? Is one a subset of the other? 回答1: Dead code - code that is executed but redundant, either the results were never used or adds nothing to the rest of the program. Wastes CPU performance. function(){ // dead code since it's calculated but not saved or used anywhere a + b; } Unreachable code - code that will never be reached regardless of logic flow. Difference is

Why is destructor of boost::thread detaching joinable thread instead of calling terminate() as standard suggests?

。_饼干妹妹 提交于 2019-11-29 13:40:56
问题 According to the draft C++0x standard, this code: void simplethread() { boost::thread t(someLongRunningFunction); // Commented out detach - terminate() expected. // t.detach(); } ... should result in an terminate() call, but in current (boost 1.46.1) implementation of boost threads it doesn't, thread simply gets detached in destructor and continues on. My question is: why? I thought boost::thread is as much inline with draft standard as it gets. Is there a design reason for this? Will it be

Kernel's “container_of” - any way to make it ISO conforming?

南笙酒味 提交于 2019-11-29 06:00:36
While looking at Linux kernel's implementation of doubly linked circular lists, I've found following macro: #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) The way this works is that it returns pointer to structure given only address of one of its members: struct blabla { int value; struct list_head *list; } Thus you can get pointer to blabla (and get to "value") given only pointer to list. To my question, how would I make this as portable as possible (best case conforming to C89/C99?).