1,594 questions
2
votes
1
answer
92
views
Typescript infer real entries from object literal dictionary
I have a dictionary object, very simple:
const mydict = {
key1: "value1",
key2: "value2"
}
how do I make a type that automatically converts an object like this into entries?
...
0
votes
2
answers
160
views
Exhaustively check for all literals while allowing for type inference of the return type
I’m trying to write a Python function that satisfies three goals simultaneously:
Exhaustively checks all possible values of a Literal argument.
Avoids linter warnings like Ruff’s "too many ...
6
votes
1
answer
131
views
Rules on the choice of type for a literal whose value is too big
I was testing the behaviour of the big three (GCC, clang, MSVC).
I'm not sure what is standard-compliant.
Consider this code:
// p43.cxx
#include <type_traits>
constinit auto n1 = ...
5
votes
1
answer
158
views
Memory address of integer literals via ref in C++
#include <iostream>
using namespace std;
int main()
{
// Case 1
cout << &5; // This line fails to compile. Ok, I get this because "5" is a rvalue.
// Case 2
...
2
votes
3
answers
278
views
Why can't -2147483648 represented in hex literal?
Based on C++ documentation the size to hold hex literal grows from int -> unsigned int -> long -> unsigned long -> long long -> unsigned long long.
But I wonder how to specify hex ...
4
votes
8
answers
280
views
Grouping sets of 4 bits into nybbles in C printf
C23 added support for binary literals (0xb10100110) and for grouping them for human readability using a separator character ('). This is great for input, but how does one change the printf grouping to ...
0
votes
1
answer
38
views
mockito test data from val to literals springboot
i made a unit test, it works fine. Now i got a task to change the data from variables in the test body to literals, to make it more readable. So i did and got problem:
this test passes successfully:
...
0
votes
1
answer
386
views
Can you concatenate array literals at compile time in rust? [duplicate]
is there any way to concat array literals in rust?
For example, I want an array like [0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 9]
I can define an array [0; 8] and a [6, 9], but is there any way to write this ...
0
votes
1
answer
141
views
How do I use a literal C char constant in a comparison with Cython?
This seems rather trivial, but I couldn't find the answer myself: How do I use a literal C char constant in a comparison with Cython?
This doesn't work:
cdef fct(char c):
return c == 'x'
sh$ ...
-2
votes
1
answer
81
views
Unterminated regexp literal at <h1>About</h1>
I use this sample code from Custom handlers | Fresh docs:
import { Handlers } from "$fresh/server.ts";
export const handler: Handlers = {
async GET(_req, ctx) {
const resp = await ctx....
3
votes
2
answers
272
views
How to define a comptime array of arrays of divergent size
I am very new to zig and doing a very simple coding exercise. The question is about scoring words in scrabble and presents a table. As a sort of challenge I wanted to replicate the scoring table as an ...
0
votes
0
answers
155
views
Create a localized string with a generated comment
My framework contains a protocol that allows conforming types to describe themselves. One of its requirements is a static member containing the name of the type. This can be used as (for example) the ...
2
votes
2
answers
894
views
Python - Passing enum set to Literal
I have a question about this construct:
from enum import Enum
from typing import Literal
class Fruit(Enum):
Apple = "apple"
Bannana = "bananna"
Watermelon = "...
0
votes
0
answers
38
views
Suffixes for numerical constants in C: when should they be used? [duplicate]
I've used C for scientific programming for more than 15 years and I've never needed suffixes like F and L for numerical literals. I wonder why some very experienced programmers almost always use them....
0
votes
2
answers
948
views
C Programming - What is 2U or 8U in struct
Code from this link: https://github.com/openwch/arduino_core_ch32/blob/main/libraries/USBPD_SINK/src/usbpd_def.h
I am looking at the previous file. I did some search and found something about unsign ...
-1
votes
1
answer
562
views
Using class variables for literal values
This is more of a request for comments and critique rather than a proper question.
Context: I am using simple classes with class variables as containers for string constants. These might hold ids of ...
-3
votes
1
answer
3k
views
Python3 elevenlabs ImportError: cannot import name 'Literal' from 'typing'
enter image description here
See image. What am i doing wrong? I'm a newbie with python, i don't have a clue what i am doing wrong
ps: i previously installed the package elevenlabs with 'pip3 install ...
0
votes
2
answers
171
views
Escaping dot in if-statement with echo in Windows batch
I have a chicken-and-egg issue: I need to echo a dot in an if statement in a batch script, but the command prompt crashes, saying '. was unexpected at this time.'
Note that echoing treats everything ...
1
vote
1
answer
138
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 *...
-1
votes
1
answer
80
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 ...
0
votes
1
answer
113
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 ...
19
votes
2
answers
3k
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 ...
2
votes
4
answers
347
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 ...
3
votes
2
answers
184
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 = ...
2
votes
1
answer
884
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 ...