Questions tagged [literals]

a notation for representing fixed values in source code

Filter by
Sorted by
Tagged with
0 votes
1 answer
57 views

Python pattern match on an operator

I'm trying to build a function that would match on a operator , like - : def testM(x): match x: case (operator.sub,a,b): return operator.sub(a,b) case ('-',a, b): ...
Shawn Zhang's user avatar
  • 1,714
1 vote
1 answer
74 views

String Duplication

I wonder, is there another solution to modify to string literals and Is the solution really valid and optimal? #include <stdio.h> #include <string.h> #include <stdlib.h> char *...
Paroz's user avatar
  • 57
0 votes
0 answers
6 views

How can I create a linked list in gforth

I asked Bing how I could create a linked list in gforth and it gave me the following example: Here is an example of how to create a linked list in Gforth: : create-node ( value -- ) HERE 8 ALLOT ...
Bryan Zimmer's user avatar
-2 votes
0 answers
38 views

where the string literals will be stored in memory layout of c program? [duplicate]

for example, consider this program in C: #include <stdio.h> int main(){ char* s = "Hello World"; return 0; } If this program compiled and execute, then where will be the "...
Vignesh B's user avatar
2 votes
1 answer
68 views

How do I get PowerShell script path of and inside Batch-Powershell Hybrid script even when the path contains multiple occurrences of Square Brackets?

See the below script that I have for renaming Movie files with .mp4 or .mkv extensions: <# :: @echo off powershell -c "iex ((Get-Content -LiteralPath '%~f0') -join [Environment]::Newline); ...
Vicky Dev's user avatar
  • 1,965
0 votes
1 answer
63 views

Advantages and differences between passing string literals or const char[] to functions [closed]

let's say i have a program where i print the same line to the console multiple times throughout it's execution and the line needs to be passed to printf() multiple times. on the surface the option at ...
xXRunDeathXx's user avatar
0 votes
3 answers
104 views

What is a good way of initializing a vector of char* from string literals?

Until C++11, one was able to write the following: #include <vector> using namespace std; int main_under_test(int argc, char* argv[]) { return 0; } int main() { vector<char*> args ...
bers's user avatar
  • 4,934
0 votes
0 answers
36 views

What does =C in ENDFIL LDA =C'EOF' 032010 in SIC means

I am trying to understand the concept literals in SIC machines. I encountered a code snippet in the System Program by Leland Becks book 45 001A ENDFIL LDA =C'EOF' 032010 i am confused by what ...
Midhun Raj's user avatar
0 votes
1 answer
35 views

How to render template literals without using new Function because chrome extension manifest v3 does not permit unsafe-eval

I made a chrome extension with the v2 manifest that uses a lot of template literals coming from json files. I was rendering them using new Function which made it so easy. But with chrome extension ...
Patrick Matte's user avatar
1 vote
0 answers
54 views

Python 3.8: @typing.overload usage with typing.Literal and Enum values

According to https://peps.python.org/pep-0586/#legal-parameters-for-literal-at-type-check-time typing.Literal works with Enum values as legal parameters. But autocomplete does not work with following ...
Egor Erofeev's user avatar
0 votes
1 answer
37 views

Conditionally adding to an object literal in javascript [closed]

I would like to conditionally fill a property based on the target type. I need to do this inside an event handler for a form (react). I would like an if/else statements situations that encompasses ...
Codelleschi's user avatar
18 votes
2 answers
2k views

C++23: char now supports Unicode?

Does C++23 now provide support for Unicode characters in its basic char type, and to what degree? So on cppreference for character literals, a character literal: 'c-char' is defined as either: a ...
mishar's user avatar
  • 401
0 votes
4 answers
142 views

unsigned long long resTestBad = 0xffffffff + 1; print 0 with %llu, but unsigned long long resA = 4294967295 + 1; print 4294967296 with %llu

It seems that I found a bug when print value of (0xffffffff + 1) with %llu is 0, see below code: unsigned long long resTestBad = 0xffffffff + 1; // number of f is 8 printf("resTestBad is %llu, ...
Tom's user avatar
  • 473
2 votes
4 answers
149 views

Why are string literals lvalues and not xvalues?

Ben Saks in his lesson "Understanding Value Categories" at the 2019 CppCon in Aurora (CO) (great lesson btw) said: "Character string literals, such as "examplestring", are ...
ofkilmurray's user avatar
0 votes
1 answer
299 views

SyntaxError: invalid decimal literal (gdrive)

user_interactions_df = pd.read_csv(https://drive.google.com/uc?export=download&id=1WgjXneyZHGQrxrh1maRyPdbXE3J9wp--) ...
Harsh Lokhande 's user avatar
2 votes
2 answers
94 views

An unsigned int literal outside bounds

If I define a variable of the unsigned int type and initialize it with a value outside its bounds, it uses modulo and assigns itself a value in its range, right? For example: unsigned int a = ...
Rajdeep Sindhu's user avatar
1 vote
1 answer
108 views

What is the point of types of literals in C++?

I'm new to C++ and I'm using C++ Primer to study. To me, it makes sense for variables to have "sub-types" like long and long long for int, so that they can accommodate larger values, even if ...
Rajdeep Sindhu's user avatar
-1 votes
1 answer
143 views

Can rust slice type [T] be used without reference or pointer?

The line assigning arguably a slice literal let integers: [i32] = [ 1, 2, 3 ][..]; gives a message that integers “doesn't have a size known at compile-time”. Why is it not obvious that storage space ...
Bernhard Bodenstorfer's user avatar
0 votes
0 answers
41 views

Object Literals in JavaScript - Where declare correctly Globals and Constants

using Object Literals in JavaScript, what's the best way to declare CONSTANTS and GLOBALS within the object itself? (if that's the best way to do it) For the example below, I need to know, how can I ...
zokk7's user avatar
  • 398
1 vote
2 answers
136 views

Is there any difference between bool foo = true and bool foo = 1?

In C++, is there any difference between assigning a bool to true and assigning it to 1(or any non-zero integer)? I have seen many competitive programmers use 1 instead of true even when the code is ...
Youssef Gamil's user avatar
-1 votes
1 answer
73 views

Error 14 error C2041: illegal digit '8' for base '8'

while compiling this the switch statement got error in case 8 and 9 srand(time(0)); int random = (rand() %10) + 1; LogDebug.Log (atmID, 2, iThreadNo, "sendTransacMsgToRDV&...
Syed Omer Gohar's user avatar
0 votes
1 answer
98 views

How to avoid repeating literals in type annotations

Challenge: Define literals (and their types for function annotations), but only write the literal value once. Real-life example: A port can be allocated a VLAN, or a list of VLANs, or can be defined ...
Netcreator's user avatar
0 votes
1 answer
115 views

C Error while using compound literals: array initialized from non-constant array expression

I am trying to initialize an array of size 2 via compound literals, the code with error is as below int a[2] = (int[2]){1,2}; And the gcc compiler returns the bug saying error: array initialized from ...
fdc's user avatar
  • 3
0 votes
0 answers
76 views

String with literal_eval

can someone help me here? what is going on? why the string without(key=name) the spaces work and the string with(key=caption) the spaces fail? import ast a = {'caption': 'A silhouette of two wine ...
Shon Otmazgin's user avatar
0 votes
0 answers
51 views

Storage of literals in Java [duplicate]

Where are integer or double literals stored in Java? Are they stored in the .class file or in permanent generation space (now in metaspace)?
xyz xyz's user avatar
  • 21
-6 votes
2 answers
404 views

Why does the literal string """"""" (seven quotes) give an error? [duplicate]

Processing client's input we often use the strip() method. If we want to remove starting-ending symbols from some specific set we just place all it in the parameter. The code: ".yes' "....
Vasyl Kolomiets's user avatar
-1 votes
1 answer
153 views

Integer literal in Java?

int x = 10; Here 10 is directly assigned to variable x or 10 is stored somewhere else and then it get assigned to variable x? I have read in one of the stackoverlow answer that Java stores literals ...
xyz's user avatar
  • 17
-1 votes
1 answer
57 views

How to get a Memory Address (Pointer) from a Number Literal?

Background: I have decided to work with neutral void pointers (void*) in my programme because it is uniform, efficient and I can cast them to whatever is needed in the context. When calling a ...
Christian Heller's user avatar
0 votes
1 answer
119 views

overloading functions to use with both variables and literals - ambiguous call error

I'm trying to overload some functions to work with several data types. This is trivial when I'm passing variables as parameters, thusly: void fnc(int32_t d){ Serial.println((String) "int32 = &...
Robert M.'s user avatar
  • 582
0 votes
1 answer
47 views

Memory allocation for same string literals

Consider this code: int main(void) { printf("%s", "the string"); printf("%s", "the string"); } Is there any standard saying that the program memory ...
Łukasz Przeniosło's user avatar
0 votes
0 answers
51 views

What Non-Literals May Be Used When Declaring a VBA Constant?

Background I am using an R script to generate VBA code. To be fully dynamic, the R script must infer its parameters from numeric Constants in an existing VBA module. Since the set of legal names for R ...
Greg's user avatar
  • 3,046
3 votes
0 answers
329 views

C# 11 String Literal, triple quote multiline not working

I've been using the new C# string literal feature for a bit and it's been great, but for some reason in a new project .NET7.0, Blazor Server, I am getting the following error RZ1000 Unterminated ...
EyeSeeSharp's user avatar
5 votes
1 answer
419 views

how do I declare and initialize an array of bytes in C++

Is this really the best way to declare a byte (or array of bytes)? static constexpr byte kGuard1_[] = { byte{0x45}, byte{0x23}, byte{0x12}, byte{0x56}, byte{0x99}, byte{0x76}, byte{0x12}, ...
lewis's user avatar
  • 1,156
1 vote
1 answer
100 views

Typescript Overriding Type of String Literals

I currently have the following setup: enum EnumA { A, AYE } enum EnumB { B, BEE } type A = keyof typeof EnumA type B = keyof typeof EnumB type AB = A | B interface IBase { foo:...
JasonBourne's user avatar
2 votes
1 answer
400 views

python types: Literal of logging level as type?

the following code: import logging print(type(1)) print(type(logging.WARNING)) prints: <class 'int'> <class 'int'> yet, according to mypy, the first line of this code snippet is legal, ...
Vince's user avatar
  • 4,029
0 votes
1 answer
89 views

Has anyone ever discussed adding unquote syntax to PostgreSQL dollar-quoted strings?

Remember in LISP macros you could have those back-quotes to place evaluated expressions into larger string constants? Likewise, javascript has the `backtick quoting where you can place ${2 * 5} ...
Gunther Schadow's user avatar
1 vote
1 answer
128 views

Specify type of numeric literal as `type` alias

I would like to write the equivalent of 2_u32, 7_i64, etc but where the numeric type is given by a type alias. e.g., type Number = u32; fn main() { let a = 1_Number; // invalid syntax let b = ...
BallpointBen's user avatar
  • 10.2k
-1 votes
1 answer
40 views

Typescript specify general type but keep specific keys and values

Sometimes is really useful to use as const at the end of an object declaration, that way you create a literal singleton type, the downside is that you cannot specify a type without losing the specific ...
mindlid's user avatar
  • 1,916
2 votes
2 answers
67 views

When are array literals created?

I was reading MDN documentation, and i cant understand below statement about array literal. MDN Array literals If an array is created using a literal in a top-level script, JavaScript interprets the ...
Tarun Dhiman's user avatar
0 votes
0 answers
38 views

Suffix to convert scientific notation to a type other than double [duplicate]

I'm looking for a literal which would convert scientific notation to a type other than double. In my case, i need uint64_t. It should do something like this: uint64_t x = 1e6_ui64; But I'm not sure ...
Kaiyakha's user avatar
  • 1,525
0 votes
1 answer
119 views

Getting: In ARRAY_LITERAL, an Array Literal was missing values for one or more rows when there's no details in Col11

I originally posted because I couldn't work out why I was getting Array Literal Error when I have same amount of columns in each formula. However, I worked out what throws it off but not how to ...
Shelley Gichigi's user avatar
0 votes
1 answer
44 views

`int('10**2')` raises `ValueError: invalid literal for int() with base 10: '10**2'` despite `type(10**2)` being `<class 'int'>`

int('10**2') raises ValueError: invalid literal for int() with base 10: '10**2' despite type(10**2) being <class 'int'>. I take input n as n = input(), then I do int(n). When I input 10**2, I ...
joseville's user avatar
  • 743
0 votes
0 answers
400 views

Literal types and default values in props (Vue 3 Typescript)

I am familirizing myself with Vue 3 and TypeScript. I am currently facing a problem when appling literal type for component's property. The idea is to have a border prop accepting 3 fixed values (sm, ...
truongleit's user avatar
6 votes
1 answer
3k views

Python type hints: How to use Literal with strings to conform with mypy?

I want to restrict the possible input arguments by using typing.Literal. The following code works just fine, however, mypy is complaining. from typing import Literal def literal_func(string_input: ...
Andi's user avatar
  • 3,403
2 votes
2 answers
152 views

What is the definition of the "literal" '\1' in the c language?

I would like to know the definition of the character/literal '\1' in the c language. Or more generally the definition of '\x' where latex{x\in\N} (is a natural number 0,1,2,3,4,5,6,...etc.) I wrote ...
kittykat's user avatar
0 votes
1 answer
94 views

How do I write float max in float literal form and parse it?

Float max/min is ...
Ned's user avatar
  • 33
1 vote
2 answers
76 views

Understanding how the "is" operator works int Python for result from function

For example we have this code. x = 1 y = 1 print(x is y) # TRUE print(id(x), id(y)) y = pow(10, 30, 10**30-1) # 1 print(type(y)) print(x, y, x is y) # FALSE It`s return: True 140516304938720 ...
Ли Шеньшунь's user avatar
1 vote
1 answer
1k views

Autocomplete in typescript of literal type and string [duplicate]

How can I create a type so that autocomplete works or you can enter any string? And is it possible? export type StateWords = | 'first' | 'second' | 'third' | string I couldn't do autofill.
Алексей Ганин's user avatar
3 votes
1 answer
2k views

Dynamic list of valid str inputs for a Pydantic Field

I need to pass in a list of valid inputs to a field in Pydantic, but I don't know what that list will include until runtime (logged-in users, date range for next 7 days, etc). Passing in multiple ...
Alex Smith's user avatar
1 vote
1 answer
234 views

Is there a technical reason why an enumerator is not a literal?

I thought that the enumerators of an enum [class] were literals, because, to my understanding, they represent for their enum [class] what 1 represents for int, true for bool, and "hello" for ...
Enlico's user avatar
  • 23.9k

1
2 3 4 5
32