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
5 answers

How can I pass the elements in a Perl array reference as separate arguments to a subroutine?

I have a list that contains arguments I want to pass to a function. How do I call that function? For example, imagine I had this function: sub foo { my ($arg0, $arg1, $arg2) = @_; print "$arg0 $arg1 $arg2\n"; } And let's say I have: my $args =…
Frank Krueger
  • 69,552
  • 46
  • 163
  • 208
6
votes
5 answers

Change the values within NSArray by dereferencing?

I've come across a problem related to pointers within arrays in objective-c. What I'm trying to do is take the pointers within an NSArray, pass them to a method, and then assign the returned value back to the original pointer(the pointer which…
Matt.M
  • 1,039
  • 3
  • 14
  • 21
6
votes
3 answers

C++ Dereferencing Arrays

I never read anything about dereferencing arrays like pointers and I believe it shouldn't work. But the following code does work using QT Creator and g++ 4.8: int ar[9]{1,2,3,4,5,6,7,8,9}; cout << *ar << endl; //prints the first element of ar Is it…
2013Asker
  • 2,008
  • 3
  • 25
  • 36
6
votes
5 answers

In C: How to set a pointer to a structure member that is an array?

How should I write my code to example a specific array index of an array that happens to be a member of a structure? The following code is giving me problems. // main.c void clean_buffers(void); // prototype struct DEV_STATUS { unsigned char…
Nate
  • 901
  • 2
  • 10
  • 19
6
votes
4 answers

Dereferencing Objects in an Array for Java Garbage Collection

I have done some research on the java garbage collector and understand that an object who is no longer referenced will/should be handled by the garbage collector. In terms of arrays-of-objects, I am aware that assigning a new object to a location in…
TIER 0011
  • 971
  • 3
  • 8
  • 13
5
votes
4 answers

In C, why is dereferenced array pointer identical to the pointer itself?

In the code below, I declare an int array "a" and then a pointer to the entire array "ap": int main(){ int a[3] = {10, 100, 1000}; int (*ap)[] = &a; printf("%p\n", ap); printf("%p\n", *ap); printf("%d\n",…
john987
  • 65
  • 4
5
votes
6 answers

Dereferencing the integer value of a for loop in java

I just figured out that when I do this in Java: for(int x = 0; x < 3; x++) { String bla = "bla"; bla += x.toString(); } It (Netbeans in this case) will tell me I can not dereference my x integer in such a manner (as I would in C#). Why is…
Mnescat
  • 195
  • 1
  • 13
5
votes
3 answers

Perl referencing and deferencing hash values when passing to subroutine?

I've been banging my head over this issue for about 5 hours now, I'm really frustrated and need some assistance. I'm writing a Perl script that pulls jobs out of a MySQL table and then preforms various database admin tasks. The current task is…
djswartz
  • 157
  • 1
  • 1
  • 8
5
votes
2 answers

What's the difference between `.map(f)` and `.map(|x| f(x))`?

When doing rustlings standard_library_types/iterators2.rs, I started wondering how std::iter::Iterator::map calls its argument closure/function. More specifically, suppose I have a function // "hello" -> "Hello" pub fn capitalize_first(input: &str)…
nalzok
  • 14,965
  • 21
  • 72
  • 139
5
votes
2 answers

what does this line of code "#define LIBINJECTION_SQLI_TOKEN_SIZE sizeof(((stoken_t*)(0))->val)" do?

In particular I'd like to know what ->val does in the sizeof(((stoken_t*)(0))->val) and what stoken_t*(0) pointer do, in particular what the (0) means? I hope I have formulated my question clearly enough.
Houst
  • 65
  • 5
5
votes
1 answer

Perl Hashes: $hash{key} vs $hash->{key}

Perl newb here, sorry for a silly question, but googling -> for a coding context is tough... Sometimes, I will access a hash like this: $hash{key} and sometimes that doesn't work, so I access it like this $hash->{key}. What's going on here? Why does…
solidau
  • 4,021
  • 3
  • 24
  • 45
5
votes
3 answers

Rustlings thread exercise, why do I NOT dereference Mutex(Struct)?

I'm learning Rust and have no experience with threads. I'm going through the Rustlings course and I've solved the threads1.rs exercise, but I don't understand why my Mutex struct doesn't need to be dereferenced. use std::sync::{Arc, Mutex}; use…
5
votes
2 answers

Can I avoid referencing + dereferencing the hash returned from a map operation?

I've got an array of hashes. I want the a list of the values in a key of those hashes based on the uniqueness of another key. my @obs = ({ value => 'three', id => 3 },{ value => 'one-2', id => 1 },{ value => 'one', id => 1 }); #…
wes
  • 7,795
  • 6
  • 31
  • 41
5
votes
3 answers

Problems with dereferencing a pointer (and returning it)

Here I have a function that creates a string, assigns it to a string pointer, and returns it. I tried returning a regular string and it worked fine. But then when when I integrated the pointers and de-referenced them, my program crashed. When I…
Jota
  • 234
  • 2
  • 11
5
votes
4 answers

How to fix the Findbugs issue "Null value is guaranteed to be dereferenced" NP_GUARANTEED_DEREF

Hi I have got some code that is reported as having the NP_GUARANTEED_DEREF issue by Findbugs. Now looking at my code I don't quite understand what is wrong with it, can anyone suggest what the problem is. public void test() { String var = ""; …
AGrunewald
  • 1,735
  • 3
  • 16
  • 25