Skip to main content
Filter by
Sorted by
Tagged with
4 votes
2 answers
133 views

For background, I am working to create a version of minesweeper that runs in the terminal to become more familiar with coding bigger projects in c. I am coding in VScode, to run on a Linux server (...
Librarian of Stars's user avatar
2 votes
1 answer
113 views

In the C standard (at least, I'm looking at draft C23 WG14/N3088), section 6.7.3 Type Qualifiers states: 7 If an attempt is made to modify an object defined with a const-qualified type through the ...
Evgeny Ilyin's user avatar
6 votes
2 answers
282 views

When I have some const members variables in my class, I would like to know how to respect core guideline C.12 to keep a default copy-assignment operator. C.12: Don’t make data members const or ...
kingsjester's user avatar
0 votes
2 answers
166 views

I have a time domain simulation running timesteps are adaptive and may grow or shrink, so there aren't a fixed number of steps to a constant time. I want to produce an output every (simulation) time ...
Neil Butcher's user avatar
  • 1,074
3 votes
3 answers
199 views

This question arouse from the question "why is const in function return type, which is a const pointer, ignored?" (const pointer, not pointer to const) int* const Foo(); is identical to int*...
yoonsohchan's user avatar
2 votes
1 answer
142 views

I'm writing a chess engine in Rust and want to start using Zobrist Hashing, which requires me to pre-initialize an array of pseudo-random numbers from a constant seed. Since this array won't change, I ...
NotARealPerson's user avatar
8 votes
2 answers
274 views

I haven't found a video about const all the things ¹, but there's at least Con.3: By default, pass pointers and references to consts from the Cpp Core Guidelines. There's lots of presentations and ...
Enlico's user avatar
  • 30.3k
12 votes
1 answer
297 views

I am going through "C++ Primer", and it is mentioned that for the following code: double dval = 3.14; const int &ri = dval; //Bind a const int to a plain double object. The ...
mindentropy's user avatar
2 votes
2 answers
179 views

I've just come across such usage of Perl constants: use strict; use warnings; use constant PI => 4 * atan2(1, 1); print("The value of PI is: ${\PI}\n"); # The value of PI is: 3....
Eugene Yarmash's user avatar
8 votes
1 answer
155 views

The following code compiles on all the compilers that I tested so far: struct Alignment { struct Center { constexpr Center() {} }; static const Center CENTER; }; constexpr int foo(...
eyelash's user avatar
  • 4,126
5 votes
0 answers
144 views

CLion supports a "code inspection" named "pass value parameters by const&", which suggests you prefer passing by const& rather than by-value with a copy. When you accept ...
einpoklum's user avatar
  • 137k
-3 votes
2 answers
149 views

I tried to use constants when returning a value from a function/method, but I don't see any benefits of using it because we can't modify the returned value from inside a function. Or even from outside....
Lion King's user avatar
  • 34.1k
1 vote
0 answers
29 views

I have a complex but well-typed constant object such that no matter what the first and second level keys are, there is always a particular known key at the third level (in the example below, moons). ...
WBT's user avatar
  • 2,562
0 votes
1 answer
95 views

I come from PHP where I usually never have global constants. For instance, if I have the class Users and the method add(int $status, string $username) then the status of the user is a constant only ...
Tintenfisch's user avatar
5 votes
5 answers
420 views

I am reading modern C, and on page 66, I come across following section: Remember that value 0 is important. It is so important that it has a lot of equivalent spellings: 0, 0x0, and ’\0’ are all the ...
Nan Xiao's user avatar
  • 17.7k
2 votes
1 answer
136 views

gcc, clang, and msvc all reject the following code: #include <memory> #include <vector> int main() { auto _ = std::vector<int const>{}; // error auto _ = std::vector<...
xmllmx's user avatar
  • 44.6k
4 votes
2 answers
164 views

Related to Is it bad to declare a C-style string without const? If so, why? , but that question is about best practise, while mine is more language lawyer. Similar questions have been asked, but for C+...
Dominik Kaszewski's user avatar
9 votes
2 answers
743 views

I am trying to make an std::unordered_set whose key is of type std::tuple. The below code compiled by MSVC gives me: Error C3848 expression having type 'const _Hasher' would lose some const-volatile ...
PkDrew's user avatar
  • 2,301
3 votes
2 answers
93 views

I recently read the NASA's power of 10 rules, and thought the rule about "using the compiler's most pedantic setting" was very interesting, considering warnings exist for a reason. I already ...
Alex RD's user avatar
  • 33
1 vote
1 answer
140 views

While reading the ChaCha20 cipher's source code, I noticed something unusual. The algorithm's constants (like 0x61707865) aren't converted for endianness, yet this doesn't cause issues across ...
S-N's user avatar
  • 402
2 votes
2 answers
129 views

I was trying to understand the use of 'const' keyword with pointers from the source: GeeksforGeeks. It is mentioned that "Passing const argument value to a non-const parameter of a function isn't ...
Nehal's user avatar
  • 21
1 vote
2 answers
184 views

This answer shows that you can create a constant generic array of strings. So this code works: const AllTestJSON: TArray<String> = [ ''' [ {'Computer Webcam', TAlphaColors.Aliceblue},...
Shaun Roselt's user avatar
  • 4,361
1 vote
1 answer
159 views

I recently need to implement a Sobol sequence generator by CUDA. Now to pre-store the Sobol table, I can either use a C++ native constexpr like below: constexpr unsigned int sobol_table[NUM_DIMENSIONS]...
PkDrew's user avatar
  • 2,301
3 votes
2 answers
138 views

Does any of the C Standards describe any kind of a check to ensure that const is used and accessed appropriately with variable argument lists? If I have the following source for a function with a ...
Richard Chambers's user avatar
1 vote
0 answers
68 views

I encountered a situation when a newly created const-qualified std::valarray<size_t> is passed to another std::valarray’s subscript operator [] when defining a std::indirect_array. This worked ...
Peter's user avatar
  • 113
0 votes
0 answers
31 views

I have a class called Astro that has a list of variables for a body some of which are calculated. In the class module: Public Mass as Double Public GM As Double Public Sub Calculate() Mass = GM / 6....
moisheweiss's user avatar
6 votes
4 answers
208 views

Trying to increase robustness of a piece of embedded code - simplified like this: enum tags { TAG1, TAG2, NUM_TAGS }; const char* const vals_ok[] = { "val1", "val2" }; ...
qdot's user avatar
  • 6,555
1 vote
1 answer
90 views

Considering that the type A is defined like this: typedef struct a { const int a; } A; I know that this code is valid: A * foo = malloc(sizeof *foo); // Allocates uninitialized memory with no ...
Fayeure's user avatar
  • 1,483
9 votes
1 answer
269 views

I tried to match on a generic Result<&mut T, T> inside of a const fn, but the compiler did not let me. It would require being able to drop the value at the end of the scope, which is ...
1uigii's user avatar
  • 94
1 vote
3 answers
178 views

I'm attempting to use real constants in Python—values which cannot be modified once defined. I realize Python has no native support for constants like certain other languages (e.g., final in Java or ...
Anuraj_R's user avatar
0 votes
1 answer
97 views

So far I've been declaring my constants in the "Main" module for my workbook, below the "Option Explicit" but above the "Sub DoTheWork()." Do public constants have to be ...
mkcoehoorn's user avatar
-4 votes
2 answers
201 views

My Q: Was it possible in older compilers? Creating an ordinary pointer to a const variable in C. I saw some ytuber (2016), but now the code doesn't compile. Following code now gives error (which is OK)...
GRTsahil's user avatar
6 votes
2 answers
255 views

Let's say I have to read some configuration files to set fields of a structure. As soon as the file has been read and the structure initialized, its field's values should not be changed. I read many ...
Oodini's user avatar
  • 1,463
7 votes
1 answer
96 views

This code prints Upper, although I would want it to print Lower: #include <concepts> #include <iostream> struct X { explicit operator bool() const { return true; } }; template<...
bers's user avatar
  • 6,309
1 vote
3 answers
233 views

I know that unused variables in C typically just lead to compiler warnings, and const variables are meant to be read-only. However, I’m curious: according to the C standard, is there any scenario ...
Alphin Thomas's user avatar
2 votes
1 answer
91 views

#include <stdio.h> typedef int (*func_t)(int); int foo(int x) { return x * 2; } int main() { const func_t ptr = foo; // Works //const func_t *ptr = &foo; // Fails: why? ...
Alphin Thomas's user avatar
1 vote
2 answers
94 views

I am able to pass a const pointer as argument of a function that takes non-const pointer. Furthermore, inside the function body, I was allowed to modify its value as well with only a warning: (passing ...
nabik's user avatar
  • 77
0 votes
1 answer
67 views

I want to target an ID on my sdf-carousel-item in the code below. const carouselModal = document.querySelector("sdf-carousel-item"); const carouselSlideOne = carouselModal.querySelector("#first"...
Schneider G's user avatar
0 votes
1 answer
113 views

I have a simple Simulink model that passes a constant variable to the workspace. I've converted the Simulink model to an exe-file using Simulink Coder (with grt.tlc as the target system file). ...
superweizen's user avatar
1 vote
0 answers
75 views

When I use this code: #include "promise.hpp" #include <thread> using namespace std; int main() { stsb::promise<int> tstint = stsb::promise<int>(); thread waitthr = ...
Stas Badzi's user avatar
3 votes
2 answers
115 views

I wondered, if the const qualifier in C is the attribute of the pointer or the memory area? If I do something like: struct S { int data; } struct CS { const int data; } char *p = malloc(100); struct ...
Zoltan K.'s user avatar
  • 1,230
0 votes
2 answers
136 views

I have this MagicSgtrings class that holds some constants which I'm using in my worker service. internal class MagicStrings { public const string HttpClientName = "X_HttpClient"; ... } ...
sTx's user avatar
  • 1,295
2 votes
2 answers
120 views

In order to get in touch with PHP, I began a little website project from scratch. The project steadily grew so that now, I'm refactoring my codebase. Up until now, I made use of constants which I use ...
hschmauder's user avatar
1 vote
2 answers
1k views

I created a library that uses lazy_static to create a static HashMap that other parts of the code can reference to look up values like this: use lazy_static::lazy_static; use std::collections::HashMap;...
RBF06's user avatar
  • 2,501
1 vote
1 answer
114 views

I'm an OOP newbie and just learning classes. Why can't I create constants and use them in classes without the static specifier? Like this: class MyClass{ private: const int MyConst = 10; int ...
CikBDysFIn's user avatar
0 votes
4 answers
186 views

If I have the following code: struct point { int x; int y; }; const struct point p = {1, 2}; p.x = 3; The compiler gives me an error: "assignment of member 'x' ...
xdevel2000's user avatar
  • 21.6k
1 vote
0 answers
95 views

I have an ndarray array that is used throughout my program: Note: ndarray and nalgebra are both used here, imported as nd and na respectively. let test: nd::ArrayBase<nd::OwnedRepr<na::...
Pioneer_11's user avatar
  • 1,441
1 vote
1 answer
61 views

Say I have a const type and corresponding sub types - type Animaltype int32 const ( dogs Animaltype = iota cats ) type dogtype int32 const ( retriever dogtype = iota whippet )...
thefrollickingnerd's user avatar
2 votes
3 answers
159 views

I would like to carry out a lazy initialization of a set of (std::vector) attributes in c++. They have to be const, in the sense that after the first time they are initialized (via a get method), ...
Antonio's user avatar
  • 23
0 votes
0 answers
66 views

I was writing this function which I think is self-explanatory: char *palindromeFirstMismatch(char *s) { char *e = s + strlen(s) - 1; while (s < e && *s == *e) ++s, --e; if (s >=...
stefan's user avatar
  • 43

1
2 3 4 5
209