dereference

Optimize InputIterator dereference without making a copy if possible?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 17:30:37
问题 I have a legacy code in which the interface is defined for pointer only and I am trying to adapt some functions to take iterators. In the answers to this question Address of a dereferenced InputIterator? The case of istream_iterator it was noted that std::istream_iterators are InputIterator . However they are special among InputIterator s, because their dereference is guarantied to generate a language reference T const& . The code for a general input iterator would look like this, notice that

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

断了今生、忘了曾经 提交于 2019-12-24 09:52:50
问题 This question already has answers here : Why can't I directly assign an int to an int pointer like this: int *p = 6;? (13 answers) Closed 2 years ago . 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 integer without a cast I just

Not able to understand the notations : * and ** with pointers

妖精的绣舞 提交于 2019-12-23 09:26:59
问题 I have a problem with the pointers. I know what this does: *name I understand that this is a pointer. I've been searching but I do neither understand what this one does nor I've found helpful information **name The context is int **name, not multiplication Could someone help me? 回答1: NOTE: Without the proper context, the usage of *name and **name is ambiguous. it may portrait (a). dereference operator (b) multiplication operator Considering you're talking about a scenario like char * name;

Struct and pointer to pointer

◇◆丶佛笑我妖孽 提交于 2019-12-22 17:11:19
问题 I am learning about linked lists and how to create them in C with structs and pointers. I have an example below. From my understanding the called push() passes the beginning memory location of our struct where the head node lies as an argument. The parameter of our push() function takes a struct node as a pointer to pointer so it is passed as a reference, not an actual copy. So the first pointer of our struct node** headref is just a pointer to the memory location of our head node and the

c++ Possible null pointer dereference

≯℡__Kan透↙ 提交于 2019-12-22 08:26:15
问题 I ran cppcheck over some code to look for possible runtime errors. And it is reporting a possible null pointer dereference with the following situation: Foo* x = ... //defined somewhere ... Foo* y(x); //possible null pointer dereference. Edit: Better example for( int i = 0; i < N; i++ ) { Foo* x( ArrayOfObjsContainingFooPtr[i].FooPtr ); // line 3 if( !x ) // line 4 continue; } Error message from cppcheck: [C:\file.cpp:3]: (error) Possible null pointer dereference: x - otherwise it is

What is implicit dereference in C++

我的梦境 提交于 2019-12-21 22:46:53
问题 What exactly does implicit dereference in C++ mean? Does it mean when I pass a reference to variable into a function parameter I don't need the & in front of it to use its value? 回答1: I assume that you teaching was trying to explain the difference between pointers and references. It is relatively common (though not technically accurate) to refer to references as fancy pointers that do implicit de-referencing. int x = 5; int* xP = &x; int& xR = x; xR = 6; // If you think of a reference as a

Dereferencing pointer to incomplete type

点点圈 提交于 2019-12-20 07:24:17
问题 I am getting the following error from this piece of code, I am new to C and learning as I go along! cc -g -I /usr/lib/i386-linux-gnu -c anld.c anld.c: In function ‘main’: anld.c:379:11: error: dereferencing pointer to incomplete type Main .C file bridge_t *bridge_p = bridge_new(); //Create / init our bridge bridge_p->s = server_connect(options.server_p, options.dest_port, options.ifname_p, options.gateway_p); bridge .C file struct bridge { int s; }; bridge_t *bridge_new(void) { bridge_t

How to copy struct and dereference all pointers

半世苍凉 提交于 2019-12-20 03:50:28
问题 How do you copy the Item struct and all pointers to a new struct? type Item struct { A []*ASet `json:"a,omitempty"` B []*BSet. `json:"b,omitempty"` C []*CSet. `json:"c,omitempty"` } type ASet struct { UID string `json:"uid,omitempty"` Items []*ItemA `json:"member,omitempty"` } type ItemA struct { UID string `json:"uid,omitempty"` Portset []*PortSet `json:"portset,omitempty"` } type PortSet struct { UID string `json:"uid,omitempty"` Ports []*Port `json:"member,omitempty"` } type Port struct {

pointer to an int array gives the same address as when it is dereferenced

梦想与她 提交于 2019-12-20 03:04:22
问题 I have the following code: #include <iostream> using namespace std; int main() { int g[] = {9,8}; int (*j)[2] = &g; cout << "*(j):" << *(j) << endl; cout << "j:" << j << endl; cout << "&j:" << &j << endl; cout << "&(*j)" << &(*j) << endl; cout << "*(*j):" << *(*j) << endl; return 0; } which ouputs: *(j):0x7fff5ab37c7c j:0x7fff5ab37c7c &j:0x7fff5ab37c70 &(*j)0x7fff5ab37c7c *(*j):9 I think that j is a pointer to an array of two integer. And &g is the address of the whole array. Then j store the

Increment operator on pointer of array errors?

房东的猫 提交于 2019-12-19 19:45:00
问题 I'm trying something very simple, well supposed to be simple but it somehow is messing with me... I am trying to understand the effect of ++ on arrays when treated as pointers and pointers when treated as arrays. So, int main() { int a[4] = { 1, 4, 7, 9 }; *a = 3; *(a+1) = 4; *++a = 4; //compiler error } 1: So at *(a+1)=4 we set a[1]=4; //Happy But when *++a = 4; , I'd expect pointer a to be incremented one since ++ is precedent to * and then * kicks in and we make it equal to 4. But this