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
6
votes
1 answer

Can function pointers be de referenced

An excerpt from Object-Oriented Programming with C++ by E Balagurusamy- Using function pointers, we can allow a C++ program to select a function dynamically at run time. We can also pass a function as an argument to another function. Here, the…
VIAGC
  • 639
  • 6
  • 14
6
votes
1 answer

Unexpected auto deref behavior

when tried impl a double linked list in rust, i found below unexpected error if let Some(link) = self.tail.take() { let x = link.borrow_mut(); link.borrow_mut().next = Some(node.clone()); } else { ... } here link is inferred to be…
Turmiht Lynn
  • 71
  • 1
  • 4
6
votes
2 answers

When returning the difference between pointers of char strings, how important is the order of casting and dereferencing?

For educational purposes (yes 42 yes) I'm rewriting strncmp and a classmate just came up to me asking why I was casting my returnvalues in such a way. My suggestion was to typecast first and dereference afterwards. My logic was that I wanted to…
wandawata
  • 63
  • 3
6
votes
2 answers

Dereferencing one past the end pointer to array type

Is it well defined in c++ to dereference a one-past-the-end pointer to an array type? Consider the following code : #include #include int main() { // An array of ints int my_array[] = { 1, 2, 3 }; // Pointer to the…
François Andrieux
  • 28,148
  • 6
  • 56
  • 87
6
votes
2 answers

Dereferencing Rc> confusion in Rust

Why does the following code work? use std::rc::Rc; fn main () { let c = vec![1, 2, 3, 4, 5]; let r = Rc::new(c); println!("{:?}", (**r)[0]); } I can understand it working with single deference (println!("{:?}", (*r)[0]);). But not able…
soupybionics
  • 4,200
  • 6
  • 31
  • 43
6
votes
1 answer

Why does a mutable borrow of a closure through DerefMut not work?

I am trying to mutably borrow a mutable variable. Deref and DerefMut are implemented for Foo, but compilation fails: use std::ops::{Deref, DerefMut}; struct Foo; impl Deref for Foo { type Target = FnMut() + 'static; fn deref(&self) ->…
chabapok
  • 921
  • 1
  • 8
  • 14
6
votes
1 answer

In PHP, is it a problem to call a static class function using the -> dereferencer

I am using PHP 5.2 I have the following code: class MyClass { public function __construct() {} public static function stuff() { echo 'This is static!
'; } } $myClass = new MyClass(); MyClass::stuff(); // Reference by…
Tonto McGee
  • 495
  • 1
  • 4
  • 6
6
votes
1 answer

Dereferencing a reference

I'm reading "The C++ Programming Language (4th edition)" and I ran into this: template void for_all(C& c, Oper op) // assume that C is a container of pointers { for (auto& x : c) op(*x); // pass op() a reference to…
Meme Master
  • 147
  • 1
  • 2
  • 6
6
votes
3 answers

Should a reference to an enum be dereferenced before it is matched?

As a newcomer to Rust, I've stumbled upon two apparently valid ways of running a match on a reference type. I've defined an enum: enum Color { Red, Yellow, Green, Teal, Blue, Purple, } I want to implement a function that…
KChaloux
  • 3,918
  • 6
  • 37
  • 52
6
votes
1 answer

Dereferencing string iterator yields int

I get this error comparison between pointer and integer ('int' and 'const char *') For the following code #include #include #include using namespace std; int main() { std::string s("test string"); for(auto…
lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
6
votes
1 answer

When would the compiler be conservative regarding pointer dereferencing optimization, if at all?

So, I recently took an interest in how well the compiler (gcc (GCC) 4.8.3 being the one in question) is in optimizing pointers and pointers. Initially I created a simple integer and an integer pointer and realized operations on it so I could print…
SSWilks
  • 105
  • 8
6
votes
5 answers

Not able to understand the notations : * and ** with pointers

I have a problem with the pointers. I know what this does: *name I understand that this is a pointer. I've been searching but I do neither understand what this one does nor I've found helpful information **name The context is int **name, not…
MLMH
  • 141
  • 8
6
votes
1 answer

Swift get value from UnsafeMutablePointer using UnsafePointer

I am trying to pass contextInfo of typeUnsafeMutablePointer to UISaveVideoAtPathToSavedPhotosAlbum and use it in the callback function. For some reason I am unable to access contextInfo as a string using UnsafePointer(x).memory when I…
user2517182
  • 1,241
  • 3
  • 15
  • 37
6
votes
3 answers

PHP dereference array elements

I have 2 arrays. $result = array(); $row = array(); Row's elements are all references and is constantly changing. For each iteration of $row I want to copy the values of row into an entry of $result and not the references. I have found a few…
anomareh
  • 5,294
  • 4
  • 25
  • 22
6
votes
5 answers

Reversing a '\0' terminated C string in place?

I have some conceptual questions about reversing a null terminated C string, and clarification questions about the nature of pointers. The input might be char arr[] = "opal"; and the code: void reverse(char *str) { /* does *str = opal or does…
Opal
  • 471
  • 1
  • 7
  • 20