dereference

Why does Autovivification occur with keys() and not %{..}?

流过昼夜 提交于 2019-12-10 03:17:16
问题 This is a subtlety I found with keys() . $ perl -e 'use warnings; use strict; my $d = { "ab" => 1 }; my @e = keys(%{$d->{cd}});' $ perl -e 'use warnings; use strict; my $d = { "ab" => 1 }; my %e = %{$d->{cd}};' Can't use an undefined value as a HASH reference at -e line 1. I am most puzzled as to why the first snippet would not give an dereferencing error. When I use Data::Dumper , it becomes clear that in the first snippet, $d->{cd} , is autovivified to be {} . Why does keys need to

Swift get value from UnsafeMutablePointer<Void> using UnsafePointer<String>

六眼飞鱼酱① 提交于 2019-12-09 06:53:11
问题 I am trying to pass contextInfo of type UnsafeMutablePointer<Void> to UISaveVideoAtPathToSavedPhotosAlbum and use it in the callback function. For some reason I am unable to access contextInfo as a string using UnsafePointer<String>(x).memory when I am in the callback function. I am pretty sure it is something simple I am missing but have spent way to many hours trying to figure this out. Below is some code that I have tried. The following code works. var testStr:String = "hello"

C++ beginner question: dereference vs multiply [duplicate]

霸气de小男生 提交于 2019-12-08 16:38:18
问题 This question already has answers here : What's the meaning of * and & when applied to variable names? (2 answers) Closed 3 years ago . Just getting into C++. I'm getting constantly thrown off track when I see the symbol for multiply ( * ) being used to denote the dereferencing of a variable for example: unsigned char * pixels = vidgrabber.getPixels(); Does this throw other people off? What's the tip for getting my head around this? Thank you. p.s. I have another reasonably simple question,

instance variable access (via self) results in a null pointer dereference

会有一股神秘感。 提交于 2019-12-08 14:58:54
问题 Running an analysis on my app results in the logical error in the subject. I don't really know what that means. Below is a screen of the error: 回答1: The path it's showing you is super returning nil . If this happens, you continue to execute the method; the implicit self deference is because isShowingLandscapeView is an instance variable. You need to put all your initialisation inside the if (self) block to avoid this. 来源: https://stackoverflow.com/questions/10246945/instance-variable-access

Printing pointer to integer causes segmentation fault. Why?

孤街浪徒 提交于 2019-12-08 14:14:03
问题 #include<stdio.h> main() { int *num2=20; printf("\n\n\n%d",num2); } When I run it as it is, it prints 20 . If I use *num2 it causes segmentation fault. Why? 回答1: Why printing num was okay but *num resulted in segmentation fault? When you say, int *num2=20; . It is equivalent to int *num; /* Type:(int*) num is a pointer to an integer and hence holds address of an integer object. */ num = 20; /* Type of the value assigned to num is (int).*/ You are assigning int to int * . You should have

How does pointer dereferencing work?

天大地大妈咪最大 提交于 2019-12-08 04:53:06
问题 #define SWAP_PTRS(a, b) do { void *t = (a); (a) = (b); (b) = t; } while (0) Node* MergeLists(Node* list1, Node* list2) { Node *list = NULL, **pnext = &list; if (list2 == NULL) return list1; while (list1 != NULL) { if (list1->data > list2->data) SWAP_PTRS(list1, list2); *pnext = list1; pnext = &list1->next; list1 = *pnext; } *pnext = list2; return list; } This code is from here, the chosen answer of this question. I cannot understand 3 lines here: *pnext = list1; pnext = &list1->next; list1 =

dereferencing hash without creating a local copy

拟墨画扇 提交于 2019-12-07 14:12:00
问题 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 references and navigating around it with dereferences would be much easier. 1 #!/usr/bin/perl -w 2 use strict; 3 use warnings; 4 5 my %h; 6 sub a { 7 8 my $href = shift;

Why are the 'dereference' and the 'address of' operators on the left?

别来无恙 提交于 2019-12-07 06:36:59
问题 In C (and some other C-like languages) we have 2 unary operators for working with pointers: the dereference operator ( * ) and the 'address of' operator ( & ). They are left unary operators, which introduces an uncertainty in order of operations, for example: *ptr->field or *arr[id] The order of operations is strictly defined by the standard, but from a human perspective, it is confusing. If the * operator was a right unary operator, the order would be obvious and wouldn't require extra

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

独自空忆成欢 提交于 2019-12-07 01:59:36
问题 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 to do. So what I want is to do this: sub foo { %parms = @_; foreach $keys (key %parms) { # do something }; } but with a hashref being passed in instead of a hash.

How to determine if a type is dereferenceable in C++03?

浪尽此生 提交于 2019-12-07 00:34:29
问题 In C++03 , how do I determine if a type T is dereferenceable? By which I mean, how do I statically determine if *t would be a valid expression for t of type T ? My attempt: template<bool B, class T = void> struct enable_if { }; template<class T> struct enable_if<true, T> { typedef T type; }; unsigned char (&helper(void const *))[2]; template<class T> typename enable_if< !!sizeof(**static_cast<T *>(NULL)), unsigned char >::type helper(T *); template<class T> struct is_dereferenceable { static