literals

Are there binary literals in Java?

与世无争的帅哥 提交于 2019-12-17 16:33:43
问题 I want to declare my integer number by a binary literal. Is it possible in Java? 回答1: Starting with Java 7 you can represent integer numbers directly as binary numbers , using the form 0b (or 0B ) followed by one or more binary digits (0 or 1). For example, 0b101010 is the integer 42. Like octal and hex numbers, binary literals may represent negative numbers. If you do not have Java 7 use this: int val = Integer.parseInt("001101", 2); There are other ways to enter integer numbers: As decimal

nested struct initialization literals

♀尐吖头ヾ 提交于 2019-12-17 16:01:16
问题 How can I do this: type A struct { MemberA string } type B struct { A MemberB string } ... b := B { MemberA: "test1", MemberB: "test2", } fmt.Printf("%+v\n", b) Compiling that gives me: "unknown B field 'MemberA' in struct literal" How can I initialize MemberA (from the "parent" struct) when I provide literal struct member values like this? 回答1: While initialization the anonymous struct is only known under its type name (in your case A ). The members and functions associated with the struct

How to make eclipse “File Search” to also search inside source jars containing some text?

一个人想着一个人 提交于 2019-12-17 15:35:27
问题 I am working on a (Java) project in which I have many jars which have a source-jar file attached. Is there any way to make the eclipse "File Search" search for Java files (and txt, xml etc. for that matter) containing some string literal inside these source jars, not just in the project folder? Or is there any plugin by which this can be achieved? 回答1: Recently discovered the following plugin has beta support for searching into linked source jars: https://github.com/ajermakovics/eclipse

What is the difference between literal and variables in Python? [closed]

纵然是瞬间 提交于 2019-12-17 14:01:19
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I'm a beginner user for Python, but I get confused between literal and variables. This is what I know about a literal: "a"+"b" And variables: sentence="a"+"b" 回答1: A literal is notation for representing a fixed (

Javascript - Replacing the escape character in a string literal

和自甴很熟 提交于 2019-12-17 10:54:25
问题 I am trying to replace the backslash (escape) character in a Javascript string literal. I need to replace it with a double backslash so that I can then do a redirect: var newpath = 'file:///C:\funstuff\buildtools\viewer.html'.replace(/\\/g,"\\"); window.location = newpath; However, it seems to have no result. I don't have the option of properly escaping the backslashes before they are handled by Javascript. How can I replace (\) with (\\) so that Javascript will be happy? Thanks, Derek 回答1:

Why are compound literals in C modifiable

不想你离开。 提交于 2019-12-17 10:06:50
问题 One does usually associate 'unmodifiable' with the term literal char* str = "Hello World!"; *str = 'B'; // Bus Error! However when using compound literals, I quickly discovered they are completely modifiable (and looking at the generated machine code, you see they are pushed on the stack): char* str = (char[]){"Hello World"}; *str = 'B'; // A-Okay! I'm compiling with clang-703.0.29 . Shouldn't those two examples generate the exact same machine code? Is a compound literal really a literal, if

comparison between string literal

▼魔方 西西 提交于 2019-12-17 07:38:14
问题 This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout << "option is " << option << endl; if (option == "foo") cout << "option foo"; else if (option == "bar") cout << "opzion bar"; else cout << "???"; cout << endl; } int main() { char opt[] = "foo"; exec(opt); return 0; } generate two warning: comparison with string literal results in unspecified behaviour. Can you explain why exactly this code doesn't work, but if I change char opt[] to char *opt it

What is the datatype of string literal in C++?

房东的猫 提交于 2019-12-17 06:45:43
问题 I'm confused about the datatype of a string literal. Is it a const char * or a const char ? 回答1: It is a const char[N] (which is the same thing as char const[N] ), where N is the length of the string plus one for the terminating NUL (or just the length of the string if you define "length of a string" as already including the NUL ). This is why you can do sizeof("hello") - 1 to get the number of characters in the string (including any embedded NUL s); if it was a pointer, it wouldn't work

What is the datatype of string literal in C++?

六月ゝ 毕业季﹏ 提交于 2019-12-17 06:43:21
问题 I'm confused about the datatype of a string literal. Is it a const char * or a const char ? 回答1: It is a const char[N] (which is the same thing as char const[N] ), where N is the length of the string plus one for the terminating NUL (or just the length of the string if you define "length of a string" as already including the NUL ). This is why you can do sizeof("hello") - 1 to get the number of characters in the string (including any embedded NUL s); if it was a pointer, it wouldn't work

Deprecated conversion from string literal to 'char*'

淺唱寂寞╮ 提交于 2019-12-17 06:35:09
问题 I have a program which declares an array of strings like this: char *colors[4] = {"red", "orange", "yellow", "blue"}; But I get the above compiler warning. It compiles but I'd rather use the non-deprecated way(if there is one). I've tried to find out what it means, but I can't seem to figure it out. I've heard using 'const' before 'char' works, but it would be helpful if someone could explain what the error means. Thanks. 回答1: The strings that you enter: "red", "organge" etc are "literal",