1,217 questions
3
votes
2
answers
274
views
Is it ok to write `&*string.end()`?
I see many places in public repositories, where the first and last iterators of std::vector/std::string/std::string_view are converted into pointers using the combination of &* operators. In ...
0
votes
0
answers
108
views
Why does * return an Actual Value, instead of a Reference to that value? [duplicate]
As far as I know, when I use * with &T, the result returned by * will be an Actual Value, not a Reference to that Value.
I also know that * is actually a Method implemented for &T. I use ...
0
votes
1
answer
74
views
Performance Implications of for x in &intoIterator vs for x in intoIterator in Rust
I would like to have a better understanding of the performance implications of choosing to write for x in &intoIterator versus for x in intoIterator in Rust. For the rest of this post, I refer to ...
10
votes
1
answer
741
views
Why do compilers not warn about this null dereferencing, even when they detect it?
Consider the following program:
int main() {
int* ptr = nullptr;
return *ptr + 1;
}
(also on GodBolt)
How is it, that with "decent" warnings enabled (-Wall -Wextra), both popular ...
0
votes
0
answers
39
views
Klocwork issue CS.NRE.FUNC.MUST still showing issue after adding null check
I am getting the following issues after running Klocwork Static Code Analysis on my code. I already added the null checks but still getting this issue.
private void ShowUI(ShellWindow shell)
{
if (...
4
votes
2
answers
200
views
Is it acceptable to pass a pointer as an argument for a double pointer in C?
So I've been doing some learning projects in c, and I'm starting to get more comfortable with pointers, however I have come across some phenomena that I can't seem to find much information for.
...
0
votes
0
answers
30
views
Feedback on JSONata query for dereferencing json schema bundles
This is my first attempt at JSONata and I would appreciate any feedback.
We have a bunch of bundled json schemas to process which need de-referencing.
To illustrate, consider the simplified schema ...
3
votes
2
answers
175
views
C++ Custom iterator dereferencing as a value instead of a reference
I am trying to create some C++ types that behave as containers but generate values on the fly (for efficiency reasons).
Here is what I would ideally want (example with a container that generates zeros)...
1
vote
1
answer
148
views
Why does this C code print different values for the same pointer when cast to different types?
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("Pointer as int*: %p\n", (void*)ptr);
printf("Pointer as char*: %p\n", (...
0
votes
1
answer
158
views
Dereferencing a valid pointer results in an error [closed]
I have a pointer to a vector which I am passing into a function. The pointer is valid before being passed in, the pointer remains intact as it's being passed through, and printing it before and after ...
0
votes
1
answer
116
views
How to understand the associativity of `&*` in a chained call composed of `as_ref()` and `as_ptr()`?
I'm reading linkedlist, an example of how to implement Iterator for a linked list from Brenden Matthews's Book Idiomatic Rust (Chapter 6). The complete code can be accessed from Source code the same ...
0
votes
0
answers
84
views
Blatant null dereference inside boost::geometry
MSVC warned me about this code inside point_concept.hpp inside the class boost::geometry::concepts::Point:
template <typename P, std::size_t Dimension, std::size_t DimensionCount>
struct ...
1
vote
2
answers
159
views
Delphi: double indexing a pointer-of-array leads to “Array type required” error
A pointer of arrays is indexed once to get the array, then indexed again to get the element. This C-style trick should work with {$POINTERMATH ON}, but it definitely doesn't:
{$POINTERMATH ON}
...
...
0
votes
3
answers
191
views
Incrementing int passed by reference C++ [closed]
int x = 0;
incrementX(&x);
x has unexpected results at this point
void incrementX(int* x)
{
// value in x stays 0
*x++;
// value increments each time 1,2,3 ...
*x+=1;
}
Why ...
1
vote
1
answer
97
views
Dereferencing a Local Reference to a Global Struct Member vs. Memcpy’ing
I have a callee function invoked by a caller function that modifies the contents of a member of a field in a union. This union is nested within a strut, and the struct is globally scoped. However, the ...