dereference

Pointers on Objective-c

≡放荡痞女 提交于 2020-01-29 14:34:06
问题 From what I understand (and please correct me if I'm wrong): int x, count = 10; int *hello; hello = &count; x = *hello; Here the variables x and count are declared to be of type integer. Additionally, the variable count is assigned the value of 10. hello is a pointer to type integer. hello is then assigned the address of count. In order to access the value of count, hello must have an asterisk in front of it, ie, *hello. So, x is assigned the value of whatever is in count and in this case, 10

Can someone explain “Dereference of a null pointer” warning

﹥>﹥吖頭↗ 提交于 2020-01-25 10:01:09
问题 I've written a couple of apps which work and seem bug free (ie, they don't crash...) but I get warnings for the code below (which I use a few times) - In the @interface - GameViewController *controller; In the @implementation - -(id)initWithOwner:(GameViewController *)aController withName:(NSString *)manName { if (self = [super init]) { // do stuff } controller = aController; On that last line, it says "Dereference of a null pointer". I'm fairly new to Objective-C (and C as well) so I haven't

Moving value out of function by dereferencing a reference [duplicate]

家住魔仙堡 提交于 2020-01-25 06:52:11
问题 This question already has answers here : Why is it legal to borrow a temporary? (3 answers) Why can I return a reference to a local literal but not a variable? (1 answer) Cannot move out of borrowed content / cannot move out of behind a shared reference (1 answer) Closed last month . Given this code: struct SimpleFoo {} fn create_simplefoo() -> SimpleFoo { let foo: &SimpleFoo = &SimpleFoo {}; *foo } pub fn main() { let foo = create_simplefoo(); } I get error[E0507]: cannot move out of `*foo`

Error: In C, got the error “dereferencing pointer to incomplete type” in a struct pointer

痞子三分冷 提交于 2020-01-24 08:55:47
问题 Hello Everybody! I got the following error, while trying to test a code for the game Clever Frog: error: dereferencing pointer to incomplete type The 'full code' is at pastebin.com - here (won't expire). But I think that with the explanation below, anybody can understands. Note: I haven't implemented yet the function that will erase the allocated memory and other things. I have a struct defined in a 1.c file: #include "1.h" ... struct test { int a; }; ... I have a 1.h wicth have the typedef

Kernel crash when dereferencing a null pointer

≡放荡痞女 提交于 2020-01-17 04:58:06
问题 I have a simple module like this: #define MODULE #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> int init_module(void) { struct inode { int i_ino; }; struct dentry { struct inode *d_inode; }; struct dentry *f_dentry; f_dentry = NULL; struct inode * p = f_dentry->d_inode; return 0; } void cleanup_module(void) { printk("Goodbye world\n"); } And my Makefile is like this: obj-m += oops.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C

What is the difference between the vector operator [] and at()

落爺英雄遲暮 提交于 2020-01-15 09:48:47
问题 I'm messing around with a pointer to a vector of pointers std::vector<int*>* MyVector; Which I try to access using these 2 methods: MyVector->at(i); //This works MyVector[i] //This says "Expression must be a pointer to a complete object type" To my understanding, the difference between a vectors [] operator and at method is that the at method does additional boundary checks, so my question is why does the at method succeed in accessing the element whereas the [] operator does not? EDIT: Whole

Why is there no safe alternative to unique_ptr::operator*()?

守給你的承諾、 提交于 2020-01-12 12:00:13
问题 std::vector has the member function at() as a safe alternative to operator[] , so that bound checking is applied and no dangling references are created: void foo(std::vector<int> const&x) { const auto&a=x[0]; // What if x.empty()? Undefined behavior! const auto&a=x.at(0); // Throws exception if x.empty(). } However, std::unique_ptr lacks the corresponding functionality: void foo(std::unique_ptr<int> const&x) { const auto&a=*x; // What if bool(x)==false? Undefined behavior! } It would be great

Why doesn't a nested reference to an array coerce to a slice?

☆樱花仙子☆ 提交于 2020-01-11 05:15:30
问题 I read What are Rust's exact auto-dereferencing rules? from beginning to end, but I still have a question about the coercion from array to slice. Let us think about the following code: let arr: &[i32; 5] = &&&[1, 2, 3, 4, 5]; // let arr: &[i32] = &&&[1, 2, 3, 4, 5]; // Error; expected slice, found reference I would expect that &&&[1, 2, 3, 4, 5] has the type, &&&[i32; 5] and dereferences to &&[i32; 5] => &[i32; 5] => &[i32; 5] => &[i32] , but the result is different from what I expected. I

In assembly Intel x64 why should place square brackets around stdin

元气小坏坏 提交于 2020-01-06 14:28:04
问题 Today was doing exercise with calling fgets from assembly. For passing FILE* to file stream I wrote mov rdx, [stdin] . But why it should be in square brackets ? Because I do not need value of that pointer just the pointer itself. Should mention, that lea rdx, [stdin] also does not work. As I remember, it causes SIGSEGV to be sent to program. As I understand square brackets in operand of mov instruction mean same as dereferencing pointer in C. Also I know that libc is dynamically linked to my

Why can a C++ iterator be dereferenced although it isn't a pointer?

牧云@^-^@ 提交于 2020-01-05 08:02:32
问题 I'm reading C++ Primer 5th, and I encounter code that looks like this: string s("some string"); if (s.begin() != s.end()) { auto it = s.begin(); *it = toupper(*it); } it receives a value from the iterator to the first character in string s ; it is then changed to upper case by toupper() . How is it that it can be dereferenced? Shouldn't it just be a char type variable and not a pointer? 回答1: it is an iterator: In C++, an iterator is any object that, pointing to some element in a range of