pointers

Pointer Dereferencing = Program Crash

unsigned int *pMessageLength, MessageLength; char *pszParsePos; ... //DATA into pszParsePos ... printf("\nMessage Length\nb1: %d\nb2: %d\nb3: %d\nb4: %d\n", pszParsePos[1],pszParsePos[2],pszParsePos[3],pszParsePos[4]); pMessageLength= (unsigned int *)&pszParsePos[1]; MessageLength = *((unsigned int *)&pszParsePos[1]); //Program ...

Can c++ create array of pointers to different classes dynamically loaded from dll?

Can c++ create array of pointers to different classes dynamically loaded from dll? ps.without headers with class definations ...

[C++] Optional parameter for reference to pointer?

Hi, how do I the second parameter become optional? template <typename T> inline void Delete (T *&MemoryToFree, T *&MemoryToFree2 = ){ delete MemoryToFree; MemoryToFree = NULL; delete MemoryToFree2; MemoryToFree2 = NULL; } I tried several things after the = operator, like NULL, (T*)NULL etc can this be done? the only way the c...

Are array of pointers to different types possible in c++?

Are array of pointers to different types possible in c++? with example please) ...

In C: How to set a pointer to a structure member that is an array?

How should I write my code to example a specific array index of an array that happens to be a member of a structure? The following code is giving me problems. // main.c void clean_buffers(void); // prototype struct DEV_STATUS { unsigned char ADDR; unsigned char DEV_HAS_DATA; unsigned char ETH_HAS_DATA; unsigned char D...

Fortran pointer functions: why does this code's behavior depend on the order of function calls?

Context The toy Fortran code posted below calls two pointer functions. That is, both functions return a pointer. In fact, they're both array pointers. They both attempt to do the same thing, which is to return an integer array pointer referencing an integer array having three elements, 1, 2, and 3. The first function uses the pointe...

Question about pointers and objects?

Just wondering, if I statically create an object that has a pointer as a data member and then the object goes out of scope, what happens to the pointer? Chuma ...

Using SWIG with pointer to function in C struct

I'm trying to write a SWIG wrapper for a C library that uses pointers to functions in its structs. I can't figure out how to handle structs that contain function pointers. A simplified example follows. test.i: /* test.i */ %module test %{ typedef struct { int (*my_func)(int); } test_struct; int add1(int n) { return n+1; } tes...

Convert every letter from a paragraph (string) to lowercase before storing it back to the string (C Programming)

I'm trying to use the following code to convert every letters from a paragraph (strings) into lowercase letters before storing it back to the string. But the compiler wouldn't compile =( #include <stdio.h> #include <stdlib.h> #include <string.h> void spellCheck(char article[], char dictionary[]) { int i = 0; char* tempArticle; ...

Converting multidimensional arrays to pointers in c++

I have a program that looks like the following: double[4][4] startMatrix; double[4][4] inverseMatrix; initialize(startMatrix) //this puts the information I want in startMatrix I now want to calculate the inverse of startMatrix and put it into inverseMatrix. I have a library function for this purpose whose prototype is the following: ...

Array of pointers initialization.

char **arr; arr = (char **)calloc(1,sizeof(char*)); for(i = 0; i< 16; i++) if(arr[i] = (char *)calloc(1, 2*sizeof(char)) == NULL) perror("Memory cannot be allocated to arr[i]", %d); The above code throws an error inside the for loop, when i am trying to allocate memory to arr[i]. Is anything wrong with this allocation. ...

Do pointers to string literals remain valid after a function returns?

Is the pointer returned by the following function valid? const char * bool2str( bool flg ) { return flg ? "Yes" : "No"; } It works well in Visual C++ and g++. What does C++ standard say about this? ...

C++ how to get the address stored in a void pointer?

hello, how can i get the memory address of the value a pointer points to? in my case it is a void pointer. just assigning it to an uint gives me this error: Error 1 error C2440: 'return' : cannot convert from 'void *' to 'UInt32' thanks! ...

How could a pointer to a structure be an array?

This is really a noob quick question. Imagine you have a struct called "No" and the following piece of code: No *v_nos; // What does this mean? Where I took this from they were calling "v_nos" a array? Isn't it simply a pointer to a struct "No"? Thanks. ...

Getter and setter, pointers or references, and good syntax to use in c++?

Hi, I would like to know a good syntax for C++ getters and setters. private: YourClass *pMember; the setter is easy I guess: void Member(YourClass *value){ this->pMember = value; // forget about deleting etc } and the getter? should I use references or const pointers? example: YourClass &Member(){ return *this->pMember; } ...

Size of virtual pointer-C++

What is the size of virtual pointer(VPTR) for a virtual table in C++? Also this is not a homework question...just a question that came to my mind while I was reading a C++ book. ...

Not copying char arrays, function swap doesnt compile correctly and stringPtr is not modified

//In header file: class definition: class myString { public: myString(void); myString(const char *str); myString(const myString &); //copy constructor ~myString(void); //destructor void swap(myString &from); private: char *stringPtr; int stringLen; }; //in cpp file, defining them member fun...

Why/When to use (!!p) instead of (p != NULL)

In the following code, what is the benefit of using (!!p) instead of (p != NULL)? AClass *p = getInstanceOfAClass(); if( !!p ) // do something else // do something without having valid pointer ...

Cocoa Touch - how do I correctly assign a new value to a pointer w/o causing a memory leak?

I've just completed my first simple iPhone app; I'm using Instruments to find memory leaks. I am a little lost as to how to reuse pointers. I have read the Apple documentation, but I still don't understand the correct procedure. The Apple docs say, "Another typical memory leak example occurs when a developer allocates memory, assigns ...

How to have a vector of byvalue and use a vector of pointers in conjunction?

Hi! I have some vectors of class A objects: std::vector<A> *V1; std::vector<A> *V2; etc there is a function with a vector of pointers of A: std::vector<A *> *arranged; what I need to do is put the vectors from V1, V2 etc inside arranged without destroying them in the end, so I thought that a vector of pointers to those objects...