Questions tagged [literals]

a notation for representing fixed values in source code

External links

1554 questions
26
votes
2 answers

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

I'm confused about the datatype of a string literal. Is it a const char * or a const char?
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126
25
votes
3 answers

Scala Functional Literals with Implicits

Forgive me if this has already been asked elsewhere. I have a Scala syntax question involving function-values and implicit parameters. I'm comfortable using implicits with Scala's currying feature. For instance if I had a sum function and wanted…
shj
  • 1,558
  • 17
  • 23
25
votes
4 answers

Difference between N'String' vs U'String' literals in Oracle

What is the meaning and difference between these queries? SELECT U'String' FROM dual; and SELECT N'String' FROM dual;
Ganesh
  • 486
  • 3
  • 8
  • 18
25
votes
2 answers

JavaScript: JSLint throws "Read Only

My code: note: the Slider Object is declared but omitted in the snippet below for better readability "use strict"; /*global arrayContainer, SliderInstance, DomObjects */ arrayContainer = new Slider.constructArray(); SliderInstance =…
Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
25
votes
5 answers

Is there a clean way to specify character literals in Swift?

Swift seems to be trying to deprecate the notion of a string being composed of an array of atomic characters, which makes sense for many uses, but there's an awful lot of programming that involves picking through datastructures that are ASCII for…
Alex Clark
  • 357
  • 1
  • 3
  • 5
25
votes
1 answer

Is the literal 0xffffffff int or unsigned in C++

According to this, integer literals without type suffix are always ints. However, both gcc and clang interpret 0xffffffff (or any literal which explicitly sets the sign bit other than using the -) as unsigned. Which is correct? (according to this…
Walter
  • 44,150
  • 20
  • 113
  • 196
24
votes
1 answer

Integer literal for fixed width integer types

Is there some c++ proposal for Integer literal for fixed width integer types like this? // i's type is unsigned int auto i = 10u; // j's type is uint32_t auto j = 10u32;
康桓瑋
  • 33,481
  • 5
  • 40
  • 90
24
votes
4 answers

Narrowing string to string literal union

I want to narrow a string to a string literal union. In other words, I want to check if the string is one of the possible values of my literal union, so that this will work (if the operator couldbe existed). type lit = "A" | "B" | "C"; let uni:…
iFreilicht
  • 13,271
  • 9
  • 43
  • 74
23
votes
1 answer

What do number literals with a suffix, like 0u8, mean in Rust?

I'm reading through The Rust Programming Language and have encountered this notation: 0u8. let some_u8_value = 0u8; match some_u8_value { 1 => println!("one"), 3 => println!("three"), 5 => println!("five"), 7 => println!("seven"), …
Jack Steam
  • 4,500
  • 1
  • 24
  • 39
23
votes
2 answers

Why must a string be constructed at run-time?

Can C-Strings or std::strings be created as constexpr or must they be created at run-time? With gcc 4.9.2 I can do this: constexpr const char foo[] = "blee"; (Sadly the November 2013 Customer Technology Preview does not allow Visual Studio to…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
22
votes
5 answers

Python Literal r'\' Not Accepted

r'\' in Python does not work as expected. Instead of returning a string with one character (a backslash) in it, it raises a SyntaxError. r"\" does the same. This is rather cumbersome if you have a list of Windows paths like these: paths = […
Alfe
  • 56,346
  • 20
  • 107
  • 159
22
votes
2 answers

Assigning literals to terms in GHC

Out of curiosity, why is the following program 1 = 0 "hello" = "world" valid and compilable by GHC? Is this merely a bug or a feature? Thanks!
thoughtpolice
  • 479
  • 4
  • 13
22
votes
4 answers

javascript/json date literal

What's the date literal for JSON/JavaScript ( if such thing does exists? )
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
22
votes
0 answers

accessing a python int literals methods

Since everything is an object in python, even literals, we are typically allowed to call methods directly on a literal. ex: 'hello'.upper() In theory, it seems like the same thing should be allowed for int literals ex: 4.bit_length() However,…
CADBOT
  • 416
  • 2
  • 9
21
votes
4 answers

Why does this function return a different value every time?

Can someone explain the following behavior? Specifically, why does the function return a different list every time? Why isn't some-list initialized to '(0 0 0) every time the function is called? (defun foo () (let ((some-list '(0 0 0))) (incf…
user285321