pointers

How to resolve pointer alias issues?

Careless use of templates can cause bloat. One way to avoid that bloat is to have a thin typesafe template that wraps non-typesafe non-template code. To do this, the wrapper needs to provide some way for the non-template code to access things it knows nothing about. For example, in a data structure, the wrapper defines the node structs....

Typical problem on Inheritance

Possible Duplicate: Why is this not allowed in C++? Why is this not allowed in C++...?? class base { private: public: void func() { cout<<"base"; } }; class derived : private base { private: public: void func() { cout<<"derived"; ...

Inline Assembly: Passing pointers to a function and using it in that function in assembly

Guys, I'm using ARM/Cortex-A8 processor platform. I have a simple function where I have to pass two pointers to a function. These pointers are later used in that function which has only my inline assembly code This plan is only to achieve performance. function(unsigned char *input, unsigned char *output) { // What are the assembl...

strstr through pointers in c language

is this the standard code for strstr i made???? char* fstrset(char *s,char *t) { int b, i=0,j=0; while(*(s+i)!='\0') { if(*(t+j)=='\0') break; else if(*(s+i)==*(t+j)) { i++;j++;b=1; } else { i++;b=0;j=0; } } if(b==0) return((char*)NULL); else if(b==1) return(s+i-j); } ...

Pointers's pointer c++ char intialization

I'm with a doubt In initialization of this in C++: char** A_Function() { char** charList = new char*[2]; charList[0] = "abcde"; charList[1] = "fghij"; return charList; } There's no problem "on compiling this code", but I'm not sure about the behaviour. 1 - the char list: char* is on heap ok? 2 - the charList[n_positio...

Location of static pointed memory

I read that pointers passed by malloc() & calloc() get allocated memory dynamically from the heap. char *Name="Ann"; In this case, is the static string {'A','n','n','\0'} also stored in the heap? Can I modify the string using the pointer? ...

C++ Linked List Runtime Error: Unhandled Exception - Writing Location Violation

I am trying to build my own implementation of a linked list in C++. My code is compiling but apparently there is some issue with my pointers referring to invalid memory addresses. Here is my implementation: #include <iostream> #include <string> using namespace std; class Node { private: string _car; Node* nextNode...

dereferencing pointer to incomplete type

Hello, gcc 4.4.4 c89 Not sure why I am getting this error. In my header file I have the following handle.h typedef struct Handle_t Handle In my implementation file handle.c struct Handle { size_t id; char *name; }; Handle* create_handle(size_t id) { Handle *hdev = NULL; hdev = malloc(sizeof(*hdev)); /* Error */ ...

Comparison of array referencing methods

I need to print out a 3 by 3 matrix in C. I could think up of 3 different ways of doing it. Are all of them equally optimal or is one method better than the other? Function 1: Passing an 2darray, using array subscripts void printMatrix(int m[][3]) { int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",m[i][j]); } ...

Is there any way to improve this function which replaces occurrences of substrings with another string in an malloc allocated string?

Hello. I'm very new to C and I decided to make a function called str_replace which replaces strings inside strings which have been made using malloc. It appears to work but can anyone find any room for improvements. Any advice will be appreciated. I'd like to know if people think finding the number of occurrences to calculate the new s...

allocating memory for a structure

Hello, gcc 4.4.4 c89 I am keep getting a "Cannot dereference to incomplete type". However, I am sure I have my structure type complete. I return the Network_t instance that is the pointer to the allocated memory. I should be able to dereference that memory. Many thanks for any advice, I have this in my header file: driver.h typedef...

Workaround for pointers in R?

I have been implementing binary tree search algorithm recently in R, and before that I used linked array-like structures. These algorithm would be much easier if there were pointers in R (not C pointers, but references to objects). I wonder if there is a workaround. I don't know S4 at all; maybe it is possible in that framework? I would ...

How to get the length of dynamically allocated two dimensional arrays in C

The question is how to get the length of dynamically allocated 2D Arrays in C? I thought the code below should get the number of rows, but it doesn't. char** lines; /* memory allocation and data manipulation */ int length; //the number of rows length = sizeof(lines)/sizeof(char*); Any thoughts on this? ...

"pointer being freed was not allocated" Memory block will not deallocate for some reason.

Hello. I'm struggling to find why I can't free a memory block. Something must be wrong with the pointer. A memory block for a structure is made in a function and the pointer used is stored in an array. Later the pointer is taken from the array to be used to free the memory. I've figured out which free it is. I've placed "//This one" nex...

Having trouble accessing struct elements returned by a function - dereferencing pointer to incomplete type

I am new to C.This are the files and codes that I am working on. I am trying to call a function (refineMatch) implemented in a separate file from the main function. function refineMatch returns a struct. I am having problems in compiling the code which is related to accessing elements in the returned struct. The compile error occurs in m...

How to pass a "path" to an object member in C#?

Say I have public class family { public person father; public person mother; public person[] child; } public class person { public string name; public int age; } What I want to do is add a function to family that will allow me to specify the location I want a new person saved to. If there were C I would pass in a poin...

C# P/Invoke: Pointer to string as error message

I am attempting to use llvmc as a C# library using P/Invokes(because I can't find any .NET bindings). However, I've a problem. llvmc uses char** for error passing. An example would be this: char* error = NULL; LLVMVerifyModule(PointerToSomeModule, LLVMAbortProcessAction, &error); What should I do to allow this function to be used in...

C++ Pointer Trouble

So I have this array of pointers image* [] myArray; And I copy the objects in the array into a new, larger array. for (int i=0; i<maxObjects; i++){ newArray[i] = myImages[i]; } for (int i=maxObjects; i<newMaxObjects; i++){ newArray[i] = NULL; } The point of this is to resize my array. Then I delete myArray: delete [] myArray;...

pointer to void

This is kind of basic but I can't seem to get a hold on this one. Reference here Are void *p and const void *p sufficiently different? Why would a function use const void * instead of void *? ...

In C++, are changes to pointers passed to a function reflected in the calling function?

If I pass a pointer P from function f1 to function f2, and modify the contents of P in f2, will these modifications be reflected in f1 automatically? For example, if I need to delete the first node in a linked list: void f2( Node *p) { Node *tmp = p; p = p -> next; delete tmp; } Will the changes made to P be reflected in ...