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

How to make a struct field containing an Arc writable?

I have a struct that somehow must be retrieved in the form of raw pointer. pub struct BufferData { /// Memory map for pixel data pub map: Arc>, pub otherdata: i32, } I need to write into its map field, so I…
Abdillah
  • 982
  • 11
  • 28
5
votes
5 answers

Is (*x).y the same as x->y?

Is operator -> allowed to use in C instead of .? Does its availability depend on compiler we are using? Is -> operator available in the last C standard or does it come from the C++ standard? How those two differ?
user5585984
5
votes
1 answer

Understanding the Debug implementation for Vec

Trying to implement the Debug trait for a custom type I stumbled upon the implementation for Vec. I have difficulties understanding how it works. The implementation goes like this: impl fmt::Debug for Vec { fn fmt(&self, f:…
toro2k
  • 19,020
  • 7
  • 64
  • 71
5
votes
4 answers

dereferencing hash without creating a local copy

I the code bellow line 9 creates a local copy of a hash. Any changes to the %d will not provide changes to global %h variable (line: 5). I have to use reference (line: 8) to provide changes to %h. Is there any way to dereference hash in a sub…
name
  • 5,095
  • 5
  • 27
  • 36
5
votes
6 answers

What does ** mean in C?

I have a sample C program I am trying to understand. Below is a function excerpt from the source code: double** Make2DDoubleArray(int arraySizeX, int arraySizeY) { double** theArray; theArray = (double**) malloc(arraySizeX*sizeof(double*)); …
Brian
  • 7,098
  • 15
  • 56
  • 73
5
votes
1 answer

L value vs R value in C

I am answering a textbook question from this textbook. I am learning about pointers in C and have come across l-values and r-values. From my understanding: l-values are values that are defined after they are executed (++x) r-values are values that…
user3037172
  • 577
  • 1
  • 7
  • 25
5
votes
3 answers

How can I take a reference to specific hash value in Perl?

How do I create a reference to the value in a specific hash key. I tried the following but $$foo is empty. Any help is much appreciated. $hash->{1} = "one"; $hash->{2} = "two"; $hash->{3} = "three"; $foo = \${$hash->{1}}; $hash->{1} = "ONE"; #I…
dave
  • 51
  • 1
  • 2
5
votes
11 answers

Why use pointers in C++?

I am learning C++ from a game development standpoint coming from long time development in C# not related to gaming, but am having a fairly difficult time grasping the concept/use of pointers and de-referencing. I have read the two chapters in my…
Volearix
  • 1,573
  • 3
  • 23
  • 49
5
votes
2 answers

Increment operator on pointer of array errors?

I'm trying something very simple, well supposed to be simple but it somehow is messing with me... I am trying to understand the effect of ++ on arrays when treated as pointers and pointers when treated as arrays. So, int main() { int a[4] = { 1,…
shadowyman
  • 215
  • 3
  • 11
5
votes
2 answers

Are @{$list_ref} and @$list_ref equivalent in Perl?

I am new to Perl and am curious whether @{$list_ref} and @$list_ref are perfectly equivalent. They seem to be interchangeable, but I am nervous that there is something subtle going on that I may be missing.
Frank Krueger
  • 69,552
  • 46
  • 163
  • 208
5
votes
1 answer

Cast void pointer to uint64_t array in C

I'm currently working with a Linux kernel module and I need to access some 64-bit values stored in an array, however I first need to cast from a void pointer. I'm using the kernel function phys_to_virt which is returning a void pointer, and I'm not…
Tony
  • 3,587
  • 8
  • 44
  • 77
5
votes
3 answers

How to increment a dereferenced double pointer?

In code I would typically use: #include void dref1(char **blah) { (*blah)[0] = 'a'; (*blah)[1] = 'z'; (*blah)[2] = 0x00; } /* or */ void dref2(char **blah) { char *p = *blah; *p++ = 'w'; *p++ = 't'; *p =…
Runium
  • 1,065
  • 10
  • 21
5
votes
2 answers

Is there a convenience for safe dereferencing in Perl?

So perl5porters is discussing to add a safe dereferencing operator, to allow stuff like $ceo_car_color = $company->ceo->car->color if defined $company and defined $company->ceo and defined $company->ceo->car; to be shortened to…
Stefan Majewsky
  • 5,427
  • 2
  • 28
  • 51
5
votes
3 answers

The reason why typeglobs can be used as a reference in Perl

Sorry for may be not clear question, but I'm asking it, because I don't like to read something without understanding what I'm reading about. Here is the snippet from the "Programming Perl": Since the way in which you dereference something always…
d.k
  • 4,234
  • 2
  • 26
  • 38
4
votes
3 answers

C++: Why does casting as a pointer and then dereferencing work?

Recently I have been working on sockets in C++ and I have come across this: *(struct in_addr*)&serv_addr.sin_addr.s_addr = *(struct in_addr *)server->h_addr; While this does do what I want it to I am a little confused as to why I can't do…
Hudson Worden
  • 2,263
  • 8
  • 30
  • 45