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
13
votes
4 answers

Which of these will create a null pointer?

The standard says that dereferencing the null pointer leads to undefined behaviour. But what is "the null pointer"? In the following code, what we call "the null pointer": struct X { static X* get() { return reinterpret_cast(1); } void f() {…
big-z
  • 6,812
  • 5
  • 20
  • 19
13
votes
3 answers

C++ - Difference between (*). and ->?

Is there any difference in performance - or otherwise - between: ptr->a(); and (*ptr).a(); ?
Rachel
  • 2,181
  • 2
  • 18
  • 20
13
votes
1 answer

instance variable access (via self) results in a null pointer dereference

Running an analysis on my app results in the logical error in the subject. I don't really know what that means. Below is a screen of the error:
Diferdin
  • 1,252
  • 1
  • 14
  • 30
12
votes
4 answers

"Char cannot be dereferenced" error

I'm trying to use the char method isLetter(), which is supposed to return boolean value corresponding to whether the character is a letter. But when I call the method, I get an error stating that "char cannot be dereferenced." I don't know what it…
user658168
  • 1,215
  • 4
  • 15
  • 15
12
votes
6 answers

ptr->hello(); /* VERSUS */ (*ptr).hello();

I was learning about C++ pointers and the -> operator seemed strange to me. Instead of ptr->hello(); one could write (*ptr).hello(); because it also seems to work, so I thought the former is just a more convenient way. Is that the case or is there…
Joey
  • 444
  • 2
  • 7
11
votes
3 answers

Is a closure for dereferencing variables useful?

I'm not sure whether or when it is useful (to improve performance) to dereference variables. var x = a.b.c.d[some_key].f; while (loop) { do_something_with(x); } seems to be better than while (loop) { …
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
11
votes
2 answers

Why is an explicit dereference required in (*x).into(), but not in x.my_into()?

After reading method-call expressions, dereference operator, method lookup, and auto-dereferencing, I thought I had a pretty good understanding of the subject; but then I encountered a situation in which I expected auto-dereferencing to happen, when…
Federico
  • 582
  • 3
  • 12
11
votes
1 answer

Unwrap and access T from an Option>>

I am trying to solve some Leetcode problems with Rust. However, I ran into some difficulties with LeetCode's TreeNode implementation. use std::cell::RefCell; use std::rc::Rc; // TreeNode data structure #[derive(Debug, PartialEq, Eq)] pub struct…
0x00A5
  • 1,462
  • 1
  • 16
  • 20
11
votes
7 answers

C++ beginner question: dereference vs multiply

Just getting into C++. I'm getting constantly thrown off track when I see the symbol for multiply (*) being used to denote the dereferencing of a variable for example: unsigned char * pixels = vidgrabber.getPixels(); Does this throw other people…
Arif Driessen
  • 587
  • 2
  • 6
  • 8
11
votes
1 answer

How to correctly dereference then delete a JavaScript Object?

I would like to know the correct way to completely dereference a JavaScript Object from memory. To ensure it's deletion without it dangling in memory, and that the garbage collector removes the object. When I looked and this question Deleting…
11
votes
4 answers

Is (*i).member less efficient than i->member

Having struct Person { string name; }; Person* p = ... Assume that no operators are overloaded. Which is more efficient (if any) ? (*p).name vs. p->name Somewhere in the back of my head I hear some bells ringing, that the * dereference…
Kalamar Obliwy
  • 861
  • 2
  • 8
  • 13
11
votes
2 answers

Dereferencing void pointers

In the hope of gaining a better understanding of the answers given in this post, can someone please explain to me if the following circular buffer implementation is possible, and if not, why not. #define CB_TYPE_CHAR 0 #define CB_TYPE_FLOAT …
Zack
  • 463
  • 2
  • 7
  • 15
10
votes
1 answer

When an immutable reference to a mutable reference to a value outside the scope is returned, why is the mutable reference dropped when the scope ends?

fn main() { // block1: fails { let mut m = 10; let n = { let b = &&mut m; &**b // just returning b fails }; println!("{:?}", n); } // block2: passes { let mut m =…
soupybionics
  • 4,200
  • 6
  • 31
  • 43
10
votes
3 answers

Resolving outer-scope references in a javascript function for serialization

var foo = (function(){ var x = "bar"; return function(){ console.log(x); }; })(); console.log(foo.toString()); // function() {console.log(x);} (foo)(); // 'bar' eval('(' + foo.toString()+')()')); // error: x is undefined Is there a…
Jacob
  • 1,642
  • 2
  • 15
  • 27
10
votes
5 answers

Can the Subversion client (svn) derefence symbolic links as if they were files?

I have a directory on a Linux system that mostly contains symlinks to files on a different filesystem. I'd like to add the directory to a Subversion repository, dereferencing the symlinks in the process (treating them as the files they point to,…
Ryan B. Lynch
  • 2,307
  • 3
  • 21
  • 21