standards

No defined type of a function parameter defaults to int? Am I insane?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 11:32:41
问题 For some odd reason I was copying an example in another language of which does not use types, and forgot to add one in to a function definition parameter, and it worked. #include <stdio.h> char toChar(n) { //sizeof n is 4 on my 32 bit system const char *alpha = \"0123456789ABCDEF\"; return alpha[n]; } int main() { putchar(toChar(15)); //i.e. return 0; } I am sure that main defaults to int by most compilers of some standard (but only return), is this also a behaviour true for other functions

Base pointer to array of derived objects

↘锁芯ラ 提交于 2019-11-26 11:27:34
问题 Following a question asked here earlier today and multitudes of similary themed questions, I\'m here to ask about this problem from stadard\'s viewpoint. struct Base { int member; }; struct Derived : Base { int another_member; }; int main() { Base* p = new Derived[10]; // (1) p[1].member = 42; // (2) delete[] p; // (3) } According to standard (1) is well-formed, because Dervied* (which is the result of new-expression ) can be implicitly converted to Base* (C++11 draft, §4.10/3): A prvalue of

Why the sizeof(bool) is not defined to be one, by the Standard itself?

◇◆丶佛笑我妖孽 提交于 2019-11-26 11:24:59
问题 Size of char , signed char and unsigned char is defined to be 1 byte, by the C++ Standard itself. I\'m wondering why it didn\'t define the sizeof(bool) also? C++03 Standard $5.3.3/1 says, sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1; the result of sizeof applied to any other fundamental type (3.9.1) is implementation-defined. [Note: in particular,sizeof(bool) and sizeof(wchar_t) are implementation-defined .69) I understand the rationale that sizeof(bool) cannot be less

Is it unspecified behavior to compare pointers to different arrays for equality?

雨燕双飞 提交于 2019-11-26 11:23:18
问题 The equality operators have the semantic restrictions of relational operators on pointers: The == (equal to) and the != (not equal to) operators have the same semantic restrictions, conversions, and result type as the relational operators except for their lower precedence and truth-value result. [C++03 §5.10p2] And the relational operators have a restriction on comparing pointers: If two pointers p and q of the same type point to different objects that are not members of the same object or

Is it legal to recurse into main() in C++? [duplicate]

独自空忆成欢 提交于 2019-11-26 11:21:23
This question already has an answer here: Can main function call itself in C++? 9 answers I read that the C++ standard forbids recursion in main() , but g++ compiles the following code without complaint: int main() { main(); } Can anyone clarify this? According to the standard in 3.6.1/3, it's not : The function main shall not be used (3.2) within a program The definition of used being : An object or non-overloaded function is used if its name appears in a potentially-evaluated expression . I'll do the fish and explain why this is verboten . Before a C or C++ program can start running, the CRT

Why don&#39;t the C or C++ standards explicitly define char as signed or unsigned?

跟風遠走 提交于 2019-11-26 11:11:05
问题 int main() { char c = 0xff; bool b = 0xff == c; // Under most C/C++ compilers\' default options, b is FALSE!!! } Neither the C or C++ standard specify char as signed or unsigned, it is implementation-defined. Why does the C/C++ standard not explicitly define char as signed or unsigned for avoiding dangerous misuses like the above code? 回答1: Historical reasons, mostly. Expressions of type char are promoted to int in most contexts (because a lot of CPUs don't have 8-bit arithmetic operations).

What&#39;s the purpose of allowing duplicate property names?

老子叫甜甜 提交于 2019-11-26 11:09:43
问题 I\'m reading the MDN javascript reference, accordingly the following code no longer returns false : function haveES6DuplicatePropertySemantics(){ \"use strict\"; try { ({ prop: 1, prop: 2 }); // No error thrown, duplicate property names allowed in strict mode return true; } catch (e) { // Error thrown, duplicates prohibited in strict mode return false; } } In ECMAScript 5 strict mode code, duplicate property names were considered a SyntaxError. With the introduction of computed property names

Spaces in URLs? [duplicate]

若如初见. 提交于 2019-11-26 10:33:53
This question already has an answer here: Is a URL allowed to contain a space? 10 answers w3fools claims that URLs can contain spaces: http://w3fools.com/#html_urlencode Is this true? How can a URL contain an un-encoded space? I'm under the impression the request line of an HTTP Request uses a space as a delimiter, being formatted as {the method}{space}{the path}{space}{the protocol} : GET /index.html http/1.1 Therefore how can a URL contain a space? If it can, where did the practice of replacing spaces with + come from? Gumbo A URL must not contain a literal space. It must either be encoded

When can you omit the file extension in an #include directive?

蓝咒 提交于 2019-11-26 10:28:53
问题 I\'m playing around with gmock and noticed it contains this line: #include <tuple> I would have expected tuple.h . When is it okay to exclude the extension, and does it give the directive a different meaning? 回答1: The C++ standard headers do not have a ".h" suffix. I believe the reason is that there were many, different pre-standard implementations that the standard would break. So instead of requiring that vendors change their exiting "iostream.h" (for example) header to be standards

<nav> or <menu> (HTML5)

依然范特西╮ 提交于 2019-11-26 10:17:15
问题 W3Schools.com and I\'m pretty sure I remember seeing W3C.org state that <menu> should be used for Toolbar menus and listing form control commands. So, which one should I use for my main menu? Nav , or Menu ? Does it matter? 回答1: nav is used for groups of internal links ( a elements). Generally this means the links should travel to separate pages, or change content in the case of an AJAX page. Expect some sort of content change when clicking on a nav item. menu is used for groups of controls (