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`).

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).

1184 questions
10
votes
3 answers

Preference between memcpy and dereference

When copying a known struct in memory, would you prefer using memcpy or dereference? why? Specifically, in the following code: #include #include typedef struct { int foo; int bar; } compound; void…
Shao-Chuan Wang
  • 980
  • 8
  • 16
9
votes
1 answer

Why does Rust not perform implicit deref coercion in match patterns?

After reading the section in the Rust book on Smart Pointers and Interior mutability, I tried, as a personal exercise, to write a function that would traverse a linked list of smart pointers and return the "last" element in the list: #[derive(Debug,…
Billy
  • 5,179
  • 2
  • 27
  • 53
9
votes
2 answers

Android app crash with null pointer dereference?

I'm developing an app, and sometimes it crashes, without any cause in my code. The only thing I have in the logcat is this: 2019-10-07 09:55:34.677 15014-15014/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 2019-10-07…
CookieMonster
  • 566
  • 2
  • 6
  • 19
9
votes
2 answers

Why is unique_ptr operator* not noexcept?

While implementing a basic std library for my hobby OS I came across this and wondered why: Both operator->() and T* get() are marked as noexcept, however operator*() is not. According to the reference it should be equivalent to *get(), which would…
Thalhammer
  • 285
  • 3
  • 7
9
votes
2 answers

Type `usize` cannot be dereferenced

I've got some code that looks somewhat like the following: let incoming: Vec = Vec::new(); match some_function(|data| { let temp = &mut incoming; Ok(*temp.write(data).unwrap()) }) { Ok(v) => v, Err(err) => return false, }; Now…
Joseph Callaars
  • 1,770
  • 1
  • 19
  • 28
9
votes
2 answers

Confusion about dereference operator ("*") in C

As far as I know, the derefence operator * returns the value stored in the pointer address. What I'm confused by is the behavior when the operator is used with pointer of an array. For example, int a[4][2]; Then a is internally converted to…
Jin
  • 1,902
  • 3
  • 15
  • 26
9
votes
3 answers

Rules for returning fake object reference in C++

I would like to iterate through a pre-allocated float array with a custom container that does not owns the data, but acts on a segment of it. Example, naming the container class LinhaSobre: std::unique_ptr data(new…
Kahler
  • 1,130
  • 6
  • 24
9
votes
3 answers

PHP 5.3.10 vs PHP 5.5.3 syntax error unexpected '['

Is it possible that this PHP code line if ($this->greatestId()["num_rows"] > 0) works in PHP 5.5 and returns an error in 5.3?? PHP Parse error: syntax error, unexpected '[' in /var/www/app/AppDAO.php on line 43 How can I change it to work under…
dendini
  • 3,842
  • 9
  • 37
  • 74
9
votes
2 answers

Dereferencing a pointer when using NSLog in Objective-C

NSDate *now = [NSDate date]; NSLog(@"This NSDate object lives at %p", now); NSLog(@"The date is %@", now); Ok, from this code, I know that now is a pointer to an NSDate object, but on the code at line 3, how can you dereference a pointer without an…
user3090658
  • 157
  • 2
  • 9
8
votes
3 answers

At what point does dereferencing the null pointer become undefined behavior?

If I don't actually access the dereferenced "object", is dereferencing the null pointer still undefined? int* p = 0; int& r = *p; // undefined? int* q = &*p; // undefined? A slightly more practical example: can I dereference the null pointer…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
8
votes
2 answers

Destructuring an Option> inside a match statement in Rust

I have a big object that I need boxed in another object but I don't necessarily need it all the time. So I want to use an if statement to get the optional boxed TempStructure but i'm not exactly sure how I can destructure and dereference at the same…
Zyansheep
  • 168
  • 2
  • 11
8
votes
1 answer

Why are trait bounds for Send on trait implementations ignored?

Why are trait bounds for auto trait Send on trait implementations ignored? (Playground(1)) trait IsSend { fn is_send(&self); } impl IsSend for T { fn is_send(&self) {} } fn main() -> Result<(), Box> { …
user1752169
  • 383
  • 2
  • 7
8
votes
4 answers

What is the meaning of "**&ptr" and "2**ptr" of C pointer?

I'm newbie on C. I need to understand what each of the values ​​printed on the screen means by the following code: #include int main() { int x = 10; int *ptr = &x; printf("%d %d %d\n", *ptr,**&ptr, 2**ptr); return…
skc
  • 139
  • 1
  • 5
8
votes
1 answer

Force allow dereference of NULL pointer

I have the very old (and huge) Win32 project which uses massive checks with NULL pointer by casting to pointer the dereferenced pointer. Like this: int* x = NULL; //somewhere //... code if (NULL == &(*(int*)x) //somewhere else return; And yes,…
user6416335
8
votes
3 answers

Address of dereferenced pointer construct

In unqlite c library I found following code: pObj = jx9VmReserveMemObj(&(*pVm),&nIdx); where pVm is: typedef struct jx9_vm jx9_vm; jx9_vm *pVm and function called is declared as: jx9_value * jx9VmReserveMemObj(jx9_vm *, sxu32 *); What for…
shibormot
  • 1,638
  • 2
  • 12
  • 23