language-lawyer

Definition of `int foo() {}` vs `int foo(void) {}` following declaration of `int foo(void);` [duplicate]

ε祈祈猫儿з 提交于 2020-04-13 06:39:11
问题 This question already has answers here : func() vs func(void) in c99 (4 answers) Closed last month . Note: this is not the same as func() vs func(void) in c99, because the question here specifically asks about the implementation of a zero-argument function following a valid declaration . Should the implementation of a zero-argument include the void keyword? Specifically, does the C standard have anything to say about the implementation of the following two functions? Note that both foo1 and

Why doesn't the scroll bar appear even if it protrudes to the left?

六月ゝ 毕业季﹏ 提交于 2020-04-13 03:59:32
问题 I created this code. This overflows to the right, which causes a scrollbar to appear: .content { position: absolute; height: 100px; width: 100px; right: -50px; top: 50px; } <div class="content"> CONTENT </div> However, this code, which extends to the left, did not generate scrollbars. I interpreted from the W3C specification that this would create scrollbars in both directions. The overflow-x property specifies the handling of overflow in the horizontal direction (i.e., overflow from the left

Can a static variable be initialized with a static constant?

北慕城南 提交于 2020-04-13 03:53:50
问题 In this answer I basically needed static int n = -1; inside a function. I wanted to avoid magic numbers so I used this instead: double f(int i) { static const int sentinel = -1; static int n = sentinel; if (n == sentinel) // ... } It was however pointed to me that this is not conformant to standard because sentinel is not a (compile time) constant. This makes sense to me since I know constant integers were made usable in compile time expressions (e.g. size of arrays) in C++. However gcc,

Can a static variable be initialized with a static constant?

不羁的心 提交于 2020-04-13 03:53:48
问题 In this answer I basically needed static int n = -1; inside a function. I wanted to avoid magic numbers so I used this instead: double f(int i) { static const int sentinel = -1; static int n = sentinel; if (n == sentinel) // ... } It was however pointed to me that this is not conformant to standard because sentinel is not a (compile time) constant. This makes sense to me since I know constant integers were made usable in compile time expressions (e.g. size of arrays) in C++. However gcc,

Is this “elision failure” language-mandated?

自闭症网瘾萝莉.ら 提交于 2020-04-13 03:53:08
问题 Consider the following code: #include <utility> #include <string> int bar() { std::pair<int, std::string> p { 123, "Hey... no small-string optimization for me please!" }; return p.first; } (simplified thanks to @Jarod42 :-) ...) I expect the function to be implemented as simply: bar(): mov eax, 123 ret but instead, the implementation calls operator new() , constructs an std::string with my literal, then calls operator delete() . At least - that's what gcc 9 and clang 9 do (GodBolt). Here's

technical legality of incompatible pointer assignments

*爱你&永不变心* 提交于 2020-04-12 09:38:29
问题 The C11 standard ISO/IEC 9899:2011 (E) states the following constraints for simple assignments in §6.5.16.1/1: One of the following shall hold: the left operand has atomic, qualified, or unqualified arithmetic type, and the right has arithmetic type; the left operand has an atomic, qualified, or unqualified version of a structure or union type compatible with the type of the right; the left operand has atomic, qualified, or unqualified pointer type, and (considering the type the left operand

Multiple Default Constructors

╄→гoц情女王★ 提交于 2020-04-11 08:38:11
问题 From this stack overflow question the answer contains this quote: ... definition says that all default constructors (in case there are multiple) ... How can there be multiple default constructors, and why may that be useful or allowed by the standard? 回答1: Default constructors don't have to have no parameters; they just need to be invocable with no arguments. This condition is fulfilled by any constructor whose arguments all have defaults. [class.dtor/1]: A default constructor for a class X

Is it allowed to use decltype in an initializer for the variable that is decltyped?

大憨熊 提交于 2020-04-11 06:11:10
问题 Triggered by this question, I was wondering if, this is allowed: template <typename T> T foo(){return T{};} struct bar {}; int main() { bar a = foo<decltype(a)>(); } Compilers I tried took it without complaints, but I am not sure if this is really legal or if I am missing any pitfalls (and it looks weird to use the type of a during its declaration). For background: in the linked question OP wants to avoid auto and spelling out the type (here it is bar , SomeComplexTypeAndNotAuto in that

Is it allowed to use decltype in an initializer for the variable that is decltyped?

点点圈 提交于 2020-04-11 06:10:52
问题 Triggered by this question, I was wondering if, this is allowed: template <typename T> T foo(){return T{};} struct bar {}; int main() { bar a = foo<decltype(a)>(); } Compilers I tried took it without complaints, but I am not sure if this is really legal or if I am missing any pitfalls (and it looks weird to use the type of a during its declaration). For background: in the linked question OP wants to avoid auto and spelling out the type (here it is bar , SomeComplexTypeAndNotAuto in that

JavaScript policy on global variables / the global namespace

二次信任 提交于 2020-04-10 03:03:56
问题 Today I ran into an issue that top is a pre-existing global variable. const left = 1; const right = 2; const top = 3; const bottom = 4; console.log(left, right, top, bottom); result: Uncaught SyntaxError: Identifier 'top' has already been declared I think I've just been lucky until today that most of the time my usage of a variable called top was inside a function. How much do I need to worry about browsers adding new global variables that will break code in the future? It seems like until