dereference

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 = [ "la", "di", "da" ]; How do I call foo without writing foo($$args[0], $$args[1], $$...

Obtaining double value out of array, iphone

NSDecimalNumber *lat = [[NSDecimalNumber alloc]initWithDouble:sqlite3_column_double(selectStatement, 1)]; [latt addObject:lat]; [lat release]; CLLocationCoordinate2D annot; annot.latitude = [[latt objectAtIndex:k]doubleValue]; The above 2 codes shows the creation and retrieving of double valu...

Difference between these two statements? - C++

Hi, I'm a programming student trying to better understand pointers, one of the things I learned is that you can set a pointer to NULL. My question is, what's the difference between these two statements? When would each of them return true/false? if (some_ptr == NULL) if (*some_ptr == NULL) Thanks! ...

How do I dereference a hash that's been returned from a method of a class?

I have a class with a method that returns a hash. Ordinarily, I would get the result like so: %resp = $myclass->sub($foo); And then access members of the returned hash like this: $resp{key}{subkey}; in the case of a 2d hash. I figure there must be a way to combine this into a single, elegant line, something like this: $myclass->...

Dereference arbitrary memory location in C

I'm trying to debug a program I've written. According to the debugger a particular void * holds the value 0x804b008. I'd like to be able to dereference this value (cast it to an int * and get it's value). I'm getting a Segmentation Error with this code. (The program with the void * is still running in the background btw - it's 'paused')...

How do I dereference a Perl hash reference that's been passed to a subroutine?

I'm still trying to sort out my hash dereferencing. My current problem is I am now passing a hashref to a sub, and I want to dereference it within that sub. But I'm not finding the correct method/syntax to do it. Within the sub, I want to iterate the hash keys, but the syntax for a hashref is not the same as a hash, which I know how t...

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 solutions but they all seem rather awful. $result[] = unserialize(serialize($row)); $result[...

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

Is there any difference in performance - or otherwise - between: ptr->a(); and (*ptr).a(); ? ...

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<X*>(1); } void f() { } }; int main() { X* x = 0; (*x).f(); // the null pointer? (1) x = X::get(); ...

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 want "MONEY: ONE"; print "MONEY: $$foo\n"; ...

C programming: Dereferencing pointer to incomplete type error

Hi, I am pretty rusty at C, and I'm getting a dereferencing error. Hopefully someone can help me with this? ^_^ I have a struct defined as: struct { char name[32]; int size; int start; int popularity; } stasher_file; and an array of pointers to those structs: struct stasher_file *files[TOTAL_STORAGE_SIZE]; In my code, I'm ...

c - dereferencing issue

Hi, I have simplified an issue that I've been having trying to isolate the problem, but it is not helping. I have a 2 dimensional char array to represent memory. I want to pass a reference to that simulation of memory to a function. In the function to test the contents of the memory I just want to iterate through the memory and print o...

vector iterator not dereferencable at runtime on a vector<vector<vector<A*>*>*>

Hi, I have this destructor that create error at runtime "vector iterator not dereferencable". The gridMatrix is a std::vector<std::vector<std::vector<AtomsCell< Atom<T> * > * > * > * > I added the typename and also the typedef but I still have the error. I will move for this idea of vect of vect* of vect* to use boost::multi_array I ...

Why is dereferencing a pointer called dereferencing?

Why is dereferencing called dereferencing? I'm just learning pointers properly, and I'd like to know why dereferencing is called that. It confused me as it sounds like you are removing a reference, rather than going via the pointer to the destination. Can anyone explain why it is called this? To me something like destination or pointe...

Is there performance to be gained by moving storage allocation local to a member function to its class?

Suppose I have the following C++ class: class Foo { double bar(double sth); }; double Foo::bar(double sth) { double a,b,c,d,e,f a = b = c = d = e = f = 0; /* do stuff with a..f and sth */ } The function bar() will be called millions of times in a loop. Obviously, each time it's called, the variables a..f have to be allocated....

dereferencing hash from params

Hi, This code works: my $href = shift @_; # get reference to hash my %h = %{$href}; # dereference hash This one does not: my %h = %{shift @_}; As well as this one: my %h = ${$_[0]} Why? ============================= One more time to be precisly: 1 #!/usr/bin/perl -w 2 use strict; 3 use warnings; 4 ...

dereferencing hash without creating a local copy

Hi, 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 without creating a local copy? I am asking since I have complicated record with many refer...

C pointer initialization and dereferencing, what's wrong here?

This should be super simple, but I'm not sure why the compiler is complaining here. #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int *n = 5; printf ("n: %d", *n); exit(0); } Getting the following complaints: foo.c: In function ‘main’: foo.c:6: warning: initialization makes pointer from i...

C++ Tracking primitive type value change

i have a complex program with weird bug that some int value is down to zero unexpectedly. so i want tracking this built-in type value, then i could debug easily. to do that, i made following ValueWatcher template class so i could track almost changes of value except when ValueWatcher is dereferencing. (i made these dereferencing operat...

dereferencing in a vector of pointers to objects

I'm trying to access the object (called a Vector) pointed to by a pointer held in a vector container, but I can't seem to get to it. Here are the important code snippets: int main{ Vector<double>* test = new Vector<double>(randvec<double>()); test->save(); cout << Element::vectors[0]; return 0; } Where Vector is a templ...