literals

Don't understand why you should not use an object literal at the beginning of a statement

余生长醉 提交于 2019-12-02 14:47:48
问题 Just reading some of the JS tuts on Mozilla and came across the statement "You should not use an object literal at the beginning of a statement. This will lead to an error or not behave as you expect, because the { will be interpreted as the beginning of a block." I don't understand what they mean. Could someone shed some light on this please 回答1: An object literal starts with { { name: "Paul" age: 30 } // I wish But so does a block. { if (age < 30) console.log ("He's lying again"); } When

What is the >>>= operator in C?

帅比萌擦擦* 提交于 2019-12-02 13:46:40
Given by a colleague as a puzzle, I cannot figure out how this C program actually compiles and runs. What is this >>>= operator and the strange 1P1 literal? I have tested in Clang and GCC. There are no warnings and the output is "???" #include <stdio.h> int main() { int a[2]={ 10, 1 }; while( a[ 0xFULL?'\0':-1:>>>=a<:!!0X.1P1 ] ) printf("?"); return 0; } Ilmari Karonen The line: while( a[ 0xFULL?'\0':-1:>>>=a<:!!0X.1P1 ] ) contains the digraphs :> and <: , which translate to ] and [ respectively, so it's equivalent to: while( a[ 0xFULL?'\0':-1 ] >>= a[ !!0X.1P1 ] ) The literal 0xFULL is the

javascript object literals using it's own fields

谁说我不能喝 提交于 2019-12-02 12:13:15
问题 I would like to create ONE object containing the whole config for certain component. I would liek it too be like this: var ObjectConfig = { fieldKeys : { name: "Obj. name", state: "Obj. state", color: "Obj. color" }, templates : { basicTemplate : [ ObjectConfig.fieldKeys.name, ObjectConfig.fieldKeys.state ], altTemplate : [ ObjectConfig.fieldKeys.name, ObjectConfig.fieldKeys.color ] } } But this in the right way to do it - it doesn't work. How can I achieve my goal? EDIT: Sorry, I was writing

Delimiter tens and units in c++ literals

半世苍凉 提交于 2019-12-02 11:37:22
问题 In Java I can do: int i = 1_200_200; How can I do something the same in c++? I mean what should I use instead of an underscore? 回答1: Since C++14 you can use single quotes (') for integer literal to improve the readability, e.g. int i = 1'200'200; Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler. 回答2: In C++ you can use the ordinary quote. For example #include <iostream> int main() { int x = 1'234'567; std::cout << "x = " << x << std

What are the semantics of mutably borrowing a literal in Rust? [duplicate]

雨燕双飞 提交于 2019-12-02 10:34:58
问题 This question already has answers here : Why is it legal to borrow a temporary? (3 answers) Why isn't this rvalue promoted to an lvalue as specified in the reference? (1 answer) Closed last year . I found that this is able to compile: let x = &mut 10; *x = 20; This is very confusing. What are the semantics of mutably borrowing an literal? I come from C++, where the compiler will definitely not allow me to refer to a rvalue like this: int *x = &10; int &y = 10; 回答1: Like C++, Rust has the

Don't understand why you should not use an object literal at the beginning of a statement

风流意气都作罢 提交于 2019-12-02 09:50:05
Just reading some of the JS tuts on Mozilla and came across the statement "You should not use an object literal at the beginning of a statement. This will lead to an error or not behave as you expect, because the { will be interpreted as the beginning of a block." I don't understand what they mean. Could someone shed some light on this please An object literal starts with { { name: "Paul" age: 30 } // I wish But so does a block. { if (age < 30) console.log ("He's lying again"); } When the interpreter sees "{" it has to pick one interpretation (*). It picks "block" and tries to parse your

What are the semantics of mutably borrowing a literal in Rust? [duplicate]

喜你入骨 提交于 2019-12-02 06:34:21
This question already has an answer here: Why is it legal to borrow a temporary? 3 answers Why isn't this rvalue promoted to an lvalue as specified in the reference? 1 answer I found that this is able to compile: let x = &mut 10; *x = 20; This is very confusing. What are the semantics of mutably borrowing an literal? I come from C++, where the compiler will definitely not allow me to refer to a rvalue like this: int *x = &10; int &y = 10; Like C++, Rust has the concept of rvalues and lvalue. The reference calls them value expressions (rvalue) and place expressions (lvalue). Additionally, there

How to address this instance of C4428 Visual C++ warning about a character literal?

廉价感情. 提交于 2019-12-02 04:33:52
问题 Currently Visual C++ issues C4428 warning universal-character-name encountered in source on the following code const wchar_t someMagicValue = L'\ufffd'; I'd like to address this warning and I wonder whether the following: const wchar_t someMagicValue = L'\xfffd'; will be fully equivalent code. Will the latter code be fully equivalent to the former? What could be a better option? 回答1: As commented here Compiler Warning (level 4) C4428 (VS2010) this is most likely /just a bug/ in MSVC See also

Can I write a literal initializer in Java for a non-primitive type?

我的未来我决定 提交于 2019-12-02 04:18:39
Java's literal initializers are mostly used for primitives (e.g. int i = 2 and double j = 4.2 ), but there are certain non-primitive classes that also have literal initializers (e.g. String a = "Hello" or Number z = 43 ). I am looking to implement an initializer similar to that in a class that I wrote. I have a class Numeric that extends Number , that I would like to be able to initialize as Numeric a = 43 . Is there any way that this can be done in Java, and if so, how? Here is the part of the source code for Numeric public class Numeric extends Number { private HashMap<Primitive, Number>

Where are literal strings placed and why can I return pointers to them?

五迷三道 提交于 2019-12-02 02:47:32
I stumbled upon this function in an answer to this question : /* Note: I've formatted the code for readability. */ const char * getString() { const char *x = "abcstring"; return x; } I was surprised to discover that returning a pointer to the literal string worked, and didn't segfault like I thought it would. I always assumed that literals were pushed on to the stack or put in some other temporary memory, but where limited to the scope of the function. But here it seems that they are more static than I had imagined. Are they then put into something sort of string pool that's global to the