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
3
votes
2 answers

C++ - dereferencing pointers that are elements of an array?

I have an object of a Deck class which contains a dynamically allocated array of pointers to objects of another class, PlayingCard. I'm attempting to overload the << operator (as a friend of class Deck) to output details of each card in a Deck…
3
votes
4 answers

Using pointers to access elements of a QVector

I have trouble with pointers and references to doubles. I want to access elements in QVector by names. The vector contains doubles: QVector
user1147533
  • 33
  • 1
  • 5
3
votes
3 answers

Perl : Dereference between @_ and $_

I have a question with the following Code: #!/usr/bin/perl use strict; use warnings; my %dmax=("dad" => "aaa","asd" => "bbb"); my %dmin=("dad" => "ccc","asd" => "ddd"); &foreach_schleife(\%dmax,\%dmin); sub foreach_schleife { my…
Hakan Kiyar
  • 1,199
  • 6
  • 16
  • 26
3
votes
5 answers

How to check if allocated memory is initialized or not

I am exposed to the pointer int* i, of which I only know its memory is allocated but am not sure it has been initialized to some integer or not. If I try to deference it, what would happen? In other words, how should I check if it is initialized or…
Terry Li
  • 16,870
  • 30
  • 89
  • 134
3
votes
2 answers

Internal representation of objects

So all this time I thought that when you do something like ObjectA.field1, ObjectA is just like any value on the stack and you basically access its fields. Now I was going through the notes for a class about OOP languages and realized that when you…
Cemre Mengü
  • 18,062
  • 27
  • 111
  • 169
3
votes
1 answer

Why do I need to implement `From` for both a value and a reference? Shouldn't methods be automatically dereferenced or borrowed?

The behaviour of a Rust method call is described in The Rust Reference. It states that "when looking up a method call, the receiver may be automatically dereferenced or borrowed in order to call a method." The behaviour is explained in more detail…
scottwillmoore
  • 450
  • 2
  • 9
3
votes
2 answers

How can I distinguish a pointer from a dereference in C?

int value =5; void testPointer( int* pa, int* pb) { *pa = *pb +5; *pb = value; value += 10; } How can I distingush both from each other? I dont get it
Basbla
  • 41
  • 2
3
votes
1 answer

Newtype pattern error: cannot move out of dereference of

I want to create a Wrapper around an existing type/struct. According to the Newtype pattern, as per Rust Book ch 19, "implementing Deref trait on the Wrapper to return an inner type would give access to all the underlying…
Anatoly Bugakov
  • 772
  • 1
  • 7
  • 18
3
votes
1 answer

Why the unary * operator does not have a constraint "the operand shall not be a pointer to void"?

C2x, 6.5.3.2 Address and indirection operators, Constraints, 2: The operand of the unary * operator shall have pointer type. Why there is no constraint "the operand shall not be a pointer to void"? Though it can be deduced from: C2x, 6.5.3.2…
pmor
  • 5,392
  • 4
  • 17
  • 36
3
votes
2 answers

What does *(long *) and *(int*) mean?

Could you explain what the next two lines do? // Line 1 *(long *)add1= *(long *)add2; // Line 2 *(int *)add1 = *(int *)add2; Edit 1. I add the complete block of code of the function I test. PS It is only a part of the skript. [original Skript] It…
3
votes
3 answers

C++ is there a difference between dereferencing and using dot operator, vs using the arrow operator

Let's say I have the following variable: MyObject* obj = ...; If this object has the field foo, there are two ways of accessing it: obj->foo (*obj).foo Are there any differences between using one method over the other. Or is the first method just…
David Callanan
  • 5,601
  • 7
  • 63
  • 105
3
votes
1 answer

How to dereference this array? And how do I store this array into a hash?

I'm having some trouble getting around Perl's referencing and dereferencing, I'm coming from a C++ background, so I understand dereferencing and referencing. It's just that Perl's syntax has got me thrown for a tizzy. I have this code where I'm…
Lord of Grok
  • 323
  • 3
  • 12
3
votes
1 answer

Operator precedence in `copy` implementation example

I read a few lines of code here where it looks to me like there should be some parentheses. template OutputIterator copy ( InputIterator first, InputIterator last, OutputIterator result ) { while…
sje397
  • 41,293
  • 8
  • 87
  • 103
3
votes
2 answers

cppcheck "Possible null pointer dereference". False positive or a bug?

I have this C code: #include #include
Hobber
  • 194
  • 1
  • 13
3
votes
4 answers

Assign char address to an int pointer, and consequently write an int-size piece of memory

from the book Stroustrup - Programming: Principles and practices using C++. In §17.3, about Memory, addresses and pointers, it is supposed to be allowed to assign a char* to int*: char ch1 = 'a'; char ch2 = 'b'; char ch3 = 'c'; char ch4 = 'd'; int*…
JB-Franco
  • 256
  • 1
  • 3
  • 17