literals

Why does 000 evaluate to 0 in Python 3?

落花浮王杯 提交于 2019-11-29 05:40:36
Since the octal prefix is now 0o in Python 3 it's not legal to write 0777 any more. Okay. So why is it legal to write 00 which evaluates properly to 0 whereas other digits trigger a syntax error? >>> 01 ... File "<interactive input>", line 1 01 ^ SyntaxError: invalid token >>> >>> 00 0 If one takes a look at the Lexical Analysis (Integer Literal Section) page: integer ::= decinteger | bininteger | octinteger | hexinteger decinteger ::= nonzerodigit (["_"] digit)* | "0"+(["_"] "0")* ... So that means that a decinteger either begins with a nonzero digit (followed by all possible digits and

Difference between GCC binary literals and C++14 ones?

妖精的绣舞 提交于 2019-11-29 05:36:19
C++14 seems to be coming and compilers are already trying to implement the core features of this new revision. I was having a look at GCC support for these core features and noticed something about the binary literals part: GCC implements them but seems to make a difference between GNU binary literals and C++14 binary literals. Here are the respective references for both: GNU binary literals C++1y binary literals I tried to find some differences between the two of them since GCC seems to make the difference, but could not find anything. Does any of you know more about possible

Is 0 an octal or a decimal in C? [duplicate]

无人久伴 提交于 2019-11-29 05:23:41
This question already has an answer here: Is 0 a decimal literal or an octal literal? 3 answers I have read this . It's octal in C++ and decimal in Java. But no description about C? Is it going to make any difference if 0 is octal or decimal? This is the question asked by my interviewer. I said no and I explained that it is always 0 regardless whether it is octal or decimal. Then he asked why is it considered as octal in C++ and decimal in Java. I said it's the standard. Please let me know what is it in C? Will it make any difference? Why are they different in different standards? juanchopanza

javascript/json date literal

给你一囗甜甜゛ 提交于 2019-11-29 03:19:24
What's the date literal for JSON/JavaScript ( if such thing does exists? ) Date literals were proposed and then retracted , maybe we'll see them in a future edition of the ECMA-262 specification. Since there is no Date literal in JavaScript , there is no literal for JSON either (JavaScript Object Notation wouldn't be too good a name if it couldn't be parsed by a JavaScript engine ;-)). Admittedly, this is unfortunate. Many web services will output an ISO 8601 string, e.g. 2010-03-23T23:57Z , but in order to parse it in JavaScript you would need to use a custom library, create a custom function

Is the u8 string literal necessary in C++11

五迷三道 提交于 2019-11-29 02:36:12
问题 From Wikipedia: For the purpose of enhancing support for Unicode in C++ compilers, the definition of the type char has been modified to be at least the size necessary to store an eight-bit coding of UTF-8. I'm wondering what exactly this means for writing portable applications. Is there any difference between writing this const char[] str = "Test String"; or this? const char[] str = u8"Test String"; Is there be any reason not to use the latter for every string literal in your code? What

C++ vector literals, or something like them

孤者浪人 提交于 2019-11-29 01:08:54
I'm writing some code against a C++ API that takes vectors of vectors of vectors, and it's getting tedious to write code like the following all over the place: vector<string> vs1; vs1.push_back("x"); vs1.push_back("y"); ... vector<string> vs2; ... vector<vector<string> > vvs1; vvs1.push_back(vs1); vvs1.push_back(vs2); ... vector<vector<string> > vvs2; ... vector<vector<vector<string> > > vvvs; vvvs.push_back(vvs1); vvvs.push_back(vvs2); ... Does C++ have a vector literal syntax? I.e., something like: vector<vector<vector<string>>> vvvs = { { {"x","y", ... }, ... }, ... } Is there a non-builtin

Is a literal NSString autoreleased or does it need to be released?

允我心安 提交于 2019-11-28 19:26:24
When creating a string using the following notation: NSString *foo = @"Bar"; Does one need to release foo ? Or is foo autoreleased in this case? Compiler allocated strings (of the format @"STRING") are constant, and so -retain, -release, and -autorelease messages to them are ignored. You don't have to release or autorelease foo in this case (but it won't hurt). As mentioned in the docs http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or

Make C floating point literals float (rather than double)

做~自己de王妃 提交于 2019-11-28 18:30:59
It is well known that in C, floating point literals (e.g. 1.23 ) have type double . As a consequence, any calculation that involves them is promoted to double. I'm working on an embedded real-time system that has a floating point unit that supports only single precision ( float ) numbers. All my variables are float , and this precision is sufficient. I don't need (nor can afford) double at all. But every time something like if (x < 2.5) ... is written, disaster happens: the slowdown can be up to two orders of magnitude. Of course, the direct answer is to write if (x < 2.5f) ... but this is so

What are the Java semantics of an escaped number in a character literal, e.g. '\\15' ?

删除回忆录丶 提交于 2019-11-28 16:27:33
Please explain what, exactly, happens when the following sections of code are executed: int a='\15'; System.out.println(a); this prints out 13; int a='\25'; System.out.println(a); this prints out 21; int a='\100'; System.out.println(a); this prints out 64. Bohemian You have assigned a character literal, which is delimited by single quotes, eg 'a' (as distinct from a String literal, which is delimited by double quotes, eg "a" ) to an int variable. Java does an automatic widening cast from the 16-bit unsigned char to the 32-bit signed int . However, when a character literal is a backslash

Purpose of Scala's Symbol? [duplicate]

扶醉桌前 提交于 2019-11-28 16:25:20
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What are some example use cases for symbol literals in Scala? What's the purpose of Symbol and why does it deserve some special literal syntax e. g. 'FooSymbol ? 回答1: Symbols are used where you have a closed set of identifiers that you want to be able to compare quickly. When you have two String instances they are not guaranteed to be interned[1], so to compare them you must often check their contents by