Questions tagged [dereference]
Anything related to pointer dereference, i.e. the process of determining the object which the pointer is referring to. Languages having pointer variables usually have a special operator to perform dereferencing of pointers (e.g. in C and C++, if `p` is a valid pointer, `*p` is the object pointed to by `p`).
dereference
1,207
questions
0
votes
0
answers
30
views
How to handle circular references in TypeScript when serializing objects to include `$ref` annotations
I have an object structure where circular references need to be represented using $ref annotations in the output.
Here is an example of the input and expected output :-
Input is -
const obj2 = { ...
0
votes
1
answer
70
views
What does the variable declaration `const int *__errno_location ()` inside this catch statement actually do?
While working on an exercise for my C++ class where we were working on Exception handling, I came across a puzzling issue. I initially had the following exception handler (Please don't roast the use ...
3
votes
1
answer
74
views
Is it ok to double-dereference ("**itOpt") an optional iterator?
If I have a std::optional wrapped around (say) an
std::vector::const_iterator, is it safe to access the referenced
element with two consecutive dereference (*) operators?
For example:
typedef std::...
0
votes
1
answer
95
views
Why does dereferencing a String (not &String) work in Rust?
In the following code, in calculate_length function we are sending String not &String, yet dereferencing works. I expected to get error something:
type String cannot be dereferenced
But the code ...
-3
votes
4
answers
139
views
Why pointer precedence in while loop is working differently? [closed]
*s++ evalutes right to left .
while loop inside main is evaluting as right to left but while loop outside main is working as it has precedence left to rigth why???
int main(void) {
char* s = "...
0
votes
0
answers
45
views
a function returning a dereferenced pointer has type reference? [duplicate]
In the code repository I am working on, I found the following function:
const Type & (int n)
{
...
return *this;
}
A dereferenced pointer of type * Type has type Type. How can this function have ...
0
votes
1
answer
50
views
How does Dereferencing with Traits and Trait functions with Slices and Arrays work
(I am new to rust and trying to write a little card game as an exercise and I might not have grasped some things correctly. I am trying to break down my problem/confusion as much as I can.)
I want to ...
0
votes
0
answers
27
views
MacOS Ventura/Sonoma no signal when null dereference
Ventura 13.2.1 M1
Sonoma 14.2.1 M2
In my app I have a signal handler.
When testing it with null-dereference I see that in previous MacOs versions like Monterey 12.0 x86 the signal handler is called. ...
0
votes
1
answer
130
views
Two-way mutable pointer relationship with trait DerefMut in a container-element setup?
I am trying to implement something which Rust's ownership rules almost seem designed to make impossible. But it's very simple: I want a framework containing a hashmap where the values are a class, ...
0
votes
2
answers
155
views
Does the runtime dereference of a nullptr always result in Segmentation Fault?
tl;dr
What happens if "at runtime" a pointer p such that p == nullptr is dereferenced and its "pointee" is read from/written to?
Does that imply 100% a segmentation fault because ...
2
votes
1
answer
117
views
Why does Rust compiler suggest adding '&' instead of '*' when both work?
I write a simple program in Rust. This program can compile.
use std::cell::{Ref, RefCell};
fn print_number(x: &i32) {
println!("x is {}", x);
}
fn main() {
let stack: i32 = 42;
...
0
votes
0
answers
62
views
How can the execute-around-pointer code invoke an operator->() twice, although I only dereference once? [duplicate]
Consider the following code, lifted from this page regarding the "execute around pointer" idiom":
#include <vector>
#include <iostream>
using std::vector;
class ...
3
votes
2
answers
67
views
Moving value out of the Box by dereferencing (and what it is desugared into)?
Consider the following code:
let x = String::from("123");
let bx = Box::new(x);
let dbx = *bx;
println!("{}", dbx);
//println!("{}", bx); // error ...
1
vote
1
answer
50
views
Displaying references
I have this code here.
fn main() {
// Assign a reference of type `i32`. The `&` signifies there
// is a reference being assigned.
let reference = &4;
match reference {
...
0
votes
3
answers
113
views
Why can't we do arithmetic on an operand in x86 asm?
mov rax,r9+rcx*2
Why is this invalid syntax? Doesn't this count as "mov r64,r/m64" ? I'm a beginner so I'm sorry for my ignorance.
It becomes valid when the expression is enclosed in square ...