standards

When does *not* using new work on built-ins? [duplicate]

柔情痞子 提交于 2019-12-30 18:08:14
问题 This question already has answers here : What's the difference between Array(1) and new Array(1) in JavaScript? (3 answers) What is the 'new' keyword in JavaScript? (14 answers) Closed 5 years ago . Playing with built-in JavaScript objects and constructors, I noticed something a little odd. Sometimes, it's possible to get new objects by calling a constructor without new . For example: > new Array(1,2,3,4) [1, 2, 3, 4] > Array(1,2,3,4) [1, 2, 3, 4] But sometimes this doesn't work: > Date()

When does *not* using new work on built-ins? [duplicate]

六眼飞鱼酱① 提交于 2019-12-30 18:07:13
问题 This question already has answers here : What's the difference between Array(1) and new Array(1) in JavaScript? (3 answers) What is the 'new' keyword in JavaScript? (14 answers) Closed 5 years ago . Playing with built-in JavaScript objects and constructors, I noticed something a little odd. Sometimes, it's possible to get new objects by calling a constructor without new . For example: > new Array(1,2,3,4) [1, 2, 3, 4] > Array(1,2,3,4) [1, 2, 3, 4] But sometimes this doesn't work: > Date()

Can we overload main() function in C++? [duplicate]

喜欢而已 提交于 2019-12-30 16:40:08
问题 This question already has answers here : Is main() overloaded in C++? (6 answers) Closed 2 years ago . Since C+++ allows function overloading, can we overload main() ? For example, int main(const std::string &) { return 0; } int main(int argc, char *argv[]) { return main("calling overloaded main"); } gcc-4.3.4 doesn't compile this, and gives these errors: (see at ideone) prog.cpp:4: error: first argument of ‘int main(const std::string&)’ should be ‘int’ prog.cpp:4: error: ‘int main(const std:

Can we overload main() function in C++? [duplicate]

江枫思渺然 提交于 2019-12-30 16:39:09
问题 This question already has answers here : Is main() overloaded in C++? (6 answers) Closed 2 years ago . Since C+++ allows function overloading, can we overload main() ? For example, int main(const std::string &) { return 0; } int main(int argc, char *argv[]) { return main("calling overloaded main"); } gcc-4.3.4 doesn't compile this, and gives these errors: (see at ideone) prog.cpp:4: error: first argument of ‘int main(const std::string&)’ should be ‘int’ prog.cpp:4: error: ‘int main(const std:

Are there standard aliases for modules in Python?

雨燕双飞 提交于 2019-12-30 10:25:39
问题 Following the guidelines proposed in this post, I am changing all the from module import function function(agt) by: import module as mdl mdl.function(agt) in my codes. I am trying to use commonly used aliases rather than personal ones. Is there a list of some kind on the internet summing-up all well-used aliases ? For instance, these appear to be pretty common: import numpy as np import math as m import matplotlib.pyplot as plt What about aliases for scipy.linalg , time , scipy.io , cmath and

Java label irregularity (possible bug?)

我的未来我决定 提交于 2019-12-30 08:23:14
问题 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

When is a C++ terminate handler the Right Thing(TM)?

淺唱寂寞╮ 提交于 2019-12-30 08:08:09
问题 The C++ standard provides the std::set_terminate function which lets you specify what function std::terminate should actually call. std::terminate should only get called in dire circumstances, and sure enough the situations the standard describes for when it's called are dire (e.g. an uncaught exception). When std::terminate does get called the situation seems analagous to being out of memory -- there's not really much you can sensibly do. I've read that it can be used to make sure resources

Portability of using stddef.h's offsetof rather than rolling your own

送分小仙女□ 提交于 2019-12-30 06:05:56
问题 This is a nitpicky-details question with three parts. The context is that I wish to persuade some folks that it is safe to use <stddef.h> 's definition of offsetof unconditionally rather than (under some circumstances) rolling their own. The program in question is written entirely in plain old C, so please ignore C++ entirely when answering. Part 1: When used in the same manner as the standard offsetof , does the expansion of this macro provoke undefined behavior per C89, why or why not, and

what is the purpose of the extra asterisks in php comments?

久未见 提交于 2019-12-30 03:44:11
问题 I've (finally) been reading up on PEAR (php) coding standards. What is the purpose of commenting like this: /** * Here is my comment * I Wrote this in a haiku * But why put the stars? */ As opposed to this: /* Here is a comment No haiku or anything special, but it still works! */ 回答1: The /** stuff */ document is also referred to as DocBlock notation. It's used to document PHP functions, classes, etc. /** * A test function * * @param foo $bar * @return baz */ function test(foo $bar) { return

Strict aliasing and memory locations

帅比萌擦擦* 提交于 2019-12-30 02:01:13
问题 Strict aliasing prevents us from accessing the same memory location using an incompatible type. int* i = malloc( sizeof( int ) ) ; //assuming sizeof( int ) >= sizeof( float ) *i = 123 ; float* f = ( float* )i ; *f = 3.14f ; this would be illegal according to C standard, because the compiler "knows" that int cannot accessed by a float lvalue. What if I use that pointer to point to correct memory, like this: int* i = malloc( sizeof( int ) + sizeof( float ) + MAX_PAD ) ; *i = 456 ; First I