Questions tagged [literals]

a notation for representing fixed values in source code

External links

1554 questions
41
votes
1 answer

Java hexadecimal base double literal

I am studying for java certification. And i'm curious about the java literals. I know it is possible to do something like this: int i = 0xAA; long l = 0xAAL; Also this is possible for floating-point variables: double d = 123d; float f = 123f; So I…
Bruno Calça
  • 750
  • 1
  • 7
  • 16
41
votes
5 answers

Why is it allowed to pass R-Values by const reference but not by normal reference?

The following program void display(const int& a) { cout << a ; } will work if called with a literal like this display(5); but without the const it won't work. So how can a const reference keep pointing to an R-Value (anonymous variable)?
AnotherOne
  • 854
  • 2
  • 8
  • 19
41
votes
2 answers

nested struct initialization literals

How can I do this: type A struct { MemberA string } type B struct { A A MemberB string } ... b := B { MemberA: "test1", MemberB: "test2", } fmt.Printf("%+v\n", b) Compiling that gives me: "unknown B field 'MemberA' in struct…
Brad Peabody
  • 10,917
  • 9
  • 44
  • 63
37
votes
3 answers

Type of integer literals not int by default?

I just answered this question, which asked why iterating until 10 billion in a for loop takes so much longer (the OP actually aborted it after 10 mins) than iterating until 1 billion: for (i = 0; i < 10000000000; i++) Now my and many others'…
Christian Rau
  • 45,360
  • 10
  • 108
  • 185
37
votes
2 answers

C++11 operator"" with double parameter

Consider: struct str {}; str operator"" _X(long double d) { return str(); } This compiles fine with g++ 4.7.2 Wall std=c++11 but now if I give a double : str operator"" _X(double d) { return str(); } I get the following error…
Bérenger
  • 2,678
  • 2
  • 21
  • 42
37
votes
4 answers

Is the u8 string literal necessary in C++11

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…
Lukas Schmelzeisen
  • 2,934
  • 4
  • 24
  • 30
35
votes
5 answers

Use XML Literals in C#?

Is it possible to add literal XML data within a C# code file? I'm currently using a multiline string literal but it gets messy as you can see. Any better way of doing this? string XML = @"
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
34
votes
2 answers

C++ vector literals, or something like them

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 vs1; vs1.push_back("x"); vs1.push_back("y"); ... vector
Chris Conway
  • 55,321
  • 43
  • 129
  • 155
34
votes
7 answers

Scope of (string) literals

I always try to avoid to return string literals, because I fear they aren't defined outside of the function. But I'm not sure if this is the case. Let's take, for example, this function: const char * return_a_string(void) { return "blah"; } Is…
quinmars
  • 11,175
  • 8
  • 32
  • 41
34
votes
3 answers

When should you use === vs ==, !== vs !=, etc.. in javascript?

Possible Duplicate: Javascript === vs == : Does it matter which “equal” operator I use? What are the differences between === vs == and !== vs !=? When should you use each one?
Matt
  • 5,547
  • 23
  • 82
  • 121
33
votes
7 answers

Should we generally use float literals for floats instead of the simpler double literals?

In C++ (or maybe only our compilers VC8 and VC10) 3.14 is a double literal and 3.14f is a float literal. Now I have a colleague that stated: We should use float-literals for float calculations and double-literals for double calculations as this…
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
32
votes
3 answers

'as const' combined with type?

I want to combine both having a type for a constant, and using it "as const" to get the literal types as the type: type MyType = {name: string}; const x:MyType = { name: 'test' // Autocompleted, typesafe. But Type is {name: string}, not …
user2154768
  • 890
  • 3
  • 8
  • 16
32
votes
2 answers

Passing Array to Spark Lit function

Let's say I have a numpy array a that contains the numbers 1-10: [1 2 3 4 5 6 7 8 9 10] I also have a Spark dataframe to which I want to add my numpy array a. I figure that a column of literals will do the job. This doesn't work: df =…
A. R.
  • 433
  • 1
  • 4
  • 8
32
votes
2 answers

Are there binary literals in Java?

I want to declare my integer number by a binary literal. Is it possible in Java?
Conscious
  • 1,603
  • 3
  • 18
  • 16
31
votes
5 answers

How to break a big lua string into small ones

I have a big string (a base64 encoded image) and it is 1050 characters long. How can I append a big string formed of small ones, like this in C function GetIcon() return "Bigggg string 1"\ "continuation of string"\ "continuation of…
bratao
  • 1,980
  • 3
  • 21
  • 38