Skip to main content
Filter by
Sorted by
Tagged with
6 votes
2 answers
276 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
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
8 votes
2 answers
271 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.2k
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
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
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
5 votes
5 answers
418 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
4 votes
2 answers
157 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
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
2 votes
2 answers
126 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
1 answer
157 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,281
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
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
9 votes
1 answer
260 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
0 votes
1 answer
96 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
6 votes
2 answers
251 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
1 vote
3 answers
232 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
1 vote
2 answers
93 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
111 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
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
2 votes
2 answers
119 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
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
1 vote
0 answers
94 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
2 votes
3 answers
157 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
4 votes
5 answers
222 views

I have an array of color codes, the size of which is known at compile time. I want to declare another array of the same size. But the code below throws an error. I can, of course, declare the size ...
Mike's user avatar
  • 812

1
2 3 4 5
209