pointers

Bit shift and pointer oddities in C, looking for explanations

Hi all, I discovered something odd that I can't explain. If someone here can see what or why this is happening I'd like to know. What I'm doing is taking an unsigned short containing 12 bits aligned high like this: 1111 1111 1111 0000 I then want to shif the bits so that each byte in the short hold 7bits with the MSB as a pad. The resu...

CString a = "Hello " + "World!"; Is it possible?

I'm making my own string class and I was wondering if there's any way to replace the compiler behaviour around " characters. As I said in the title I'd like to make it so that CString a = "Hello " + "World!"; would actually work and not give a compiler error telling that it can't add 2 pointers. My string class automatically converts to ...

Why address of a variable change after each execution in C?

int i=10; printf("Address of i = %u",&i); Output: Address if i = 3220204848 Output on re-execution: Address of i = 3216532594 I get a new address of i each time I execute the program. What does this signify? ...

List<MyClass*> & array question

Hi, Assuming a definition like this, void CConfigTest::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; TVITEM item = pNMTreeView->itemNew; // find the session of the selected item if(item.hItem != NULL) { HTREEITEM root, parent, node; node = item.h...

How to handle an array of pointers in Objective-C

I figured out the answer to this question, but I couldn't find the solution on here, so posting it for posterity. So, in Objective-C, how do you create an object out of a pointer in order to store it in objective-c collections (NSArray, NSDictionary, NSSet, etc) without reverting to regular C? ...

Creating a new object destroys an older object with different name in C++

First question here! So, I am having some problems with pointers in Visual C++ 2008. I'm writing a program which will control six cameras and do some processing on them so to clean things up I have created a Camera Manager class. This class handles all operations which will be carried out on all the cameras. Below this is a Camera clas...

Is this a memory leak?

char *pointer1; char *pointer2; pointer1 = new char[256]; pointer2 = pointer1; delete [] pointer1; In other words, do I have to do delete [] pointer2 as well? Thanks! ...

How can I assign pointer member with long string?

Hi, When I did the practice below to erase my pointer member and assign new value to it. (*pMyPointer).member.erase(); (*pMyPointer).member.assign("Hello"); // Successfully Than I tried more... (*pMyPointer).member.erase(); (*pMyPointer).member.assign("Long Multi Lines Format String"); // How to? If the long multi lines string can...

C and C++: Array element access pointer vs int

Is there a performance difference if you either do myarray[ i ] or store the adress of myarray[ i ] in a pointer? Edit: The pointers are all calculated during an unimportant step in my program where performance is no criteria. During the critical parts the pointers remain static and are not modified. Now the question is if these static ...

C++ pointer to different array

Assume I have an array a and an array b. Both have the same type and size but different values. Now I create 3 or so pointers that point to different elements in a, you could say a[ 0 ], a[ 4 ] and a[ 13 ]. Now if I overwrite a with b via a=b - Where will the pointers point? Do the pointers still point to their original positions in ...

What are void pointers for in C++?

My question is simple: What are void pointers for in C++? (Those things you declare with void* myptr;) What is their use? Can I make them point to a variable of any type? ...

Mmap and structure

I'm working some code including communication between processes, using semaphores. I made structure like this: typedef struct container { sem_t resource, mutex; int counter; } container; and use in that way (in main app and the same in subordinate processes) container *memory; shm_unlink("MYSHM"); //just in case fd = shm_ope...

A question on vectors, pointers and iterators

Guys, I have a midterm examination tomorrow, and I was looking over the sample paper, and I'm not sure about this question. Any help would be appreciated. Let v be a vector<Thingie*>, so that each element v[i] contains a pointer to a Thingie. If p is a vector<Thingie*>::iterator, answer the following questions: what type is p? what ty...

Create a function pointer which takes a function pointer as an argument.

I'm trying to create a function pointer that takes a function pointer as an argument, but am not sure how to go about it... I was advised to try typedef-ing one of my function pointers, but get the same error. Could someone help me with the correct syntax? int 186 main(int argc, char **argv) 187 { 188 int i; 194 typ...

Can we overload the Point object in C# so it supports doubles?

I am drawing some graphs using the Point object and I want to set it so it supports doubles as its parameters. I am working on Visual C#, WindowsConsoleApplication Thank you. ...

Pointing class property to another class with vectors

I've got a simple class, and another class that has a property that points to the first class: #include <iostream> #include <vector> using namespace std; class first{ public: int var1; }; class second{ public: first* classvar; }; Then, i've got a void that's supposed to point "classvar" to the intended iteration of the clas...

what is meant by normalization in huge pointers

Hi, I have a lot of confusion on understanding the difference between a "far" pointer and "huge" pointer, searched for it all over in google for a solution, couldnot find one. Can any one explain me the difference between the two. Also, what is the exact normalization concept related to huge pointers. Please donot give me the following...

C++ Array Of Pointers

In C++ if I want an array of pointers so that I may have them point to different objects at a latter stage what does the syntax look like. EDIT I need to clarify what I am trying to do I guess. I have a class foo that has and add method. In the add method I take a reference to class bar. I want to save that reference into a pointer arr...

"Unhandled exception"/"Access violation writing location" error with referenced array pointers

I'm trying to fill a pointer matrix with values from a text file. It's a double pointer to a simple struct with 2 ints, time and tons. void get_changes(change** &c){ ifstream file("change_data_time.prn"); //data file, time only, size is the same as tons string line, var; //string placeholders for the getlines ...

how to Clean up(destructor) a dynamic Array of pointers??

Is that Destructor is enough or do I have to iterate to delete the new nodes?? #include "stdafx.h" #include<iostream> using namespace std; struct node{ int row; int col; int value; node* next_in_row; node* next_in_col; }; class MultiLinkedListSparseArray { private: char *logfile; no...