dereference

Is a NULL pointer's dereference also equals NULL?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 13:08:21
问题 Does the following snippet compile/execute the block in the if-statement? int* pointer = NULL; int deref = *pointer; if(deref == NULL){ // will execute? } Since the pointer variable contains NULL does the dereference of this pointer variable also return NULL or will this result in a runtime error? 回答1: The result is "undefined behaviour", which may or may not trigger a runtime error, and should in any case always be avoided. 回答2: Once you set: int* pointer = NULL; pointer points to nothing.

Is size of char * same as size of int *?

蓝咒 提交于 2019-12-12 10:38:34
问题 I know: char * is a pointer to char. and int * is a pointer to int. So, i want to confirm following two things: So now suppose I am on 32 bit machine, then that means memory addresses are 32 bit wide. Thus that means size of char * and int * is both 32 bits ( 4 bytes), right ? Also is size of char * * also same as size of int * ? suppose I have: int * ptr; Thus now doing *((char * *) ptr) = 0x154 is same as *((int *) ptr) = 0x514 same, right ? ( 0x514 is just any random memory address)

Segmentation fault in iterator dereferencing

不羁的心 提交于 2019-12-12 04:14:57
问题 The code listed below triggers a segmentation fault in the iterator based loop: #include <iostream> #include <vector> class A { public: A(unsigned id = 0) {id_ = id;} unsigned get_id() {return id_;} private: unsigned id_; }; class B { public: B() {} B(std::vector<A*> entries) : entries_(entries) {} const std::vector<A*> get_entries() const { return entries_; } private: std::vector<A*> entries_; }; int main() { std::vector<A*> entries; for (unsigned i = 0; i < 5; i++) { entries.push_back(new A

Qt iterator not accessing the correct object

こ雲淡風輕ζ 提交于 2019-12-12 01:09:04
问题 I have a Hash map whose values are list (qlist) of a class called ModelBinding. This class has three attributes, one of which I change: value. Fro a reason which I don't understand, my code is copying the object and modifying that copy, when instead, I would like it to modify that instance without copying it. Question It seems to me that I am dereferencing the object and changing it. However, clearly, a copy is changed instead of the instance. Why is that? How can I change the instance

Outputting multidimensional json array to table php [multiple values]

倾然丶 夕夏残阳落幕 提交于 2019-12-11 11:36:40
问题 I have been at this for the last 9 days and can't for the life of me figure this one out. It starts by obtaining the JSON array via cURL $result = curl_exec($h); curl_close($h); var_dump(json_decode($result, true)); The output with < pre> and < /pre> is as so: array(1) { ["SE"]=> array(4) { ["errors"]=> array(0) { } ["billwith"]=> string(10) "removedInteger" ["bill_detail"]=> array(1) { ["bill_item"]=> array(48) { [0]=> array(7) { ["type1identifier_id"]=> string(5) "removed coded string " [

What does the de- prefix in dereference mean? Is there a linguistic explanation for it?

空扰寡人 提交于 2019-12-11 11:09:54
问题 I learned that * is the value-at operator and & the address-of operator. Formally known as dereferencing and referencing. Whenever I talk to someone I trip over the word dereferencing, because it reminds me of the word referencing and then I get confused. I know from how I learn that if I know what the de- prefix of dereference means I won't have this problem anymore. In the same manner I learned what ante means in poker or what an antagonist and agonist is in neuroscience (and theater w.r.t.

How to access array index when using explode() in the same line?

允我心安 提交于 2019-12-11 03:15:48
问题 Can't wrap my head around this... Say, we explode the whole thing like so: $extract = explode('tra-la-la', $big_sourse); Then we want to get a value at index 1: $finish = $extract[1]; My question is how to get it in one go, to speak so. Something similar to this: $finish = explode('tra-la-la', $big_sourse)[1]; // does not work Something like the following would work like a charm: $finish = end(explode('tra-la-la', $big_sourse)); // or $finish = array_shift(explode('tra-la-la', $big_sourse));

Why do we have to cast a void pointer to int or something else before printing the value in the memory whose address is in the pointer?

风流意气都作罢 提交于 2019-12-10 16:26:30
问题 I wonder why is it necessary to cast a void pointer to an int * or char * before printing the contents of the address in memory, even though we tell the printf() function how to interpret the data in memory? Let's say that we have the following code: int main (void) { void* c = malloc(4); printf("%d",*c); return 0; } Why it is not possible to do this? So to be clear my question is what is the reason for this being not possible? EDIT: After all the answers and research I am still not convinced

When would the compiler be conservative regarding pointer dereferencing optimization, if at all?

大憨熊 提交于 2019-12-10 14:19:13
问题 So, I recently took an interest in how well the compiler ( gcc (GCC) 4.8.3 being the one in question) is in optimizing pointers and pointers. Initially I created a simple integer and an integer pointer and realized operations on it so I could print it out. As expected, all the operations that were hard coded were optmized, through dereferenced pointer or not. call __main leaq .LC0(%rip), %rcx movl $1, %edx call printf And even after creating a function that takes in an int pointer,

What are Rust's exact auto-dereferencing rules?

一个人想着一个人 提交于 2019-12-10 13:25:06
问题 I'm learning/experimenting with Rust, and in all the elegance that I find in this language, there is one peculiarity that baffles me and seems totally out of place. Rust automatically dereferences pointers when making method calls. I made some tests to determine the exact behaviour: struct X { val: i32 } impl std::ops::Deref for X { type Target = i32; fn deref(&self) -> &i32 { &self.val } } trait M { fn m(self); } impl M for i32 { fn m(self) { println!("i32::m()"); } } impl M for X { fn m