pointers

what will be the addressing mode in assembly code generated by the compiler here ?

Suppose we've got two integer and character variables: int adad=12345; char character; Assuming we're discussing a platform in which, length of an integer variable is longer than or equal to three bytes, I want to access third byte of this integer and put it in the character variable, with that said I'd write it like this: character=...

When to return a pointer, scalar and reference in C++?

I'm moving from Java to C++ and am a bit confused of the language's flexibility. One point is that there are three ways to store objects: A pointer, a reference and a scalar (storing the object itself if I understand it correctly). I tend to use references where possible, because that is as close to Java as possible. In some cases, e.g....

Global Static Pointer Issue

This is a rather a problem from a convoluted situation. I have a static pointer sitting in one of my header files. Which is being included everywhere, this is why I put it as a static pointer. So that I can quickly initilize it in my main function so that other files can use it. The problem is this, even after I initialize it and put st...

Is there a way to know what keeps objects alive in C#

I'm trying to optimize memory usage of a program and therefore wants to remove objects when they aren't needed any longer. To check if this works correctly I wrote a console.writeline method in the destructor of the type of object I want to remove. However when I test the program, no lines are written (only when the program terminates of...

Which location address in a pointer refers to

Hi, What does the address in a pointer refer to, real address location in main memory or virtual address. Can it be configured. And if it refers to virtual address , does Memory manager needs to convert this address to real address everytime it is accessed ...

assigning a char buffer to an array of pointers

Hello, gcc 4.4.4 c89 warning assignment makes integer from pointer without a cast **devices = device_buff; warning: value computed is not used *devices++; I get the above warnings with the code below. What I am trying to do is get an input from the user. And assign that char array to an array of pointers. So my array of pointers will...

Accessing the underlying struct of a PyObject

I am working on creating a python c extension but am having difficulty finding documentation on what I want to do. I basically want to create a pointer to a cstruct and be able to have access that pointer. The sample code is below. Any help would be appreciated. typedef struct{ int x; int y; } Point; typedef struct { PyObject_HEAD ...

non-const actual param to a const formal param

The const modifier in C++ before star means that using this pointer the value pointed at cannot be changed, while the pointer itself can be made to point something else. In the below void justloadme(const int **ptr) { *ptr = new int[5]; } int main() { int *ptr = NULL; justloadme(&ptr); } justloadme function should not be...

Hashing of pointer values

Sometimes you need to take a hash function of a pointer; not the object the pointer points to, but the pointer itself. Lots of the time, folks just punt and use the pointer value as an integer, chop off some high bits to make it fit, maybe shift out known-zero bits at the bottom. Thing is, pointer values aren't necessarily well-distrib...

What is the "identity pointer" before a TTypeInfo there for?

If you poke around enough in Delphi internals, you'll find something strange and apparently undocumented about TTypeInfo records generated by the compiler. If the PTypeInfo points to a TTypeInfo record at address X, at X - 4 you'll find the next 4 bytes describe a pointer to X. For example: procedure test(info: PTypeInfo); var addr:...

Is it wrong to dereference a pointer to get a reference?

I'd much prefer to use references everywhere but the moment you use an STL container you have to use pointers unless you really want to pass complex types by value. And I feel dirty converting back to a reference, it just seems wrong. Is it? To clarify... MyType *pObj = ... MyType &obj = *pObj; Isn't this 'dirty', since you can (eve...

C# interop : handling pointer-array in unmanaged struct

I'm wrapping a few calls to the unmanaged Aubio library dll (Aubio.org), and I'm wondering what a good way is to deal with the Aubio samplebuffer. It's defined like this : // Buffer for real values struct _fvec_t { uint length; // length of buffer uint channels; // number of channels float **data; // data array of size [len...

Reading/Writing self heap

Could the own heap space be readed? could the software be self modified in memory? I write some code to show the subject, am I reading own code at memory? how (if possible) to write it and change instruction on runtime? #include<stdio.h> #include<stdint.h> volatile int addressBase; uint8_t read(int address); int main(void) { ...

c++ - pointer resistance

If *get_ii() returned heap memory, rather than stack memory, would this problem be eliminated? 01 int *get_ii() 02 { 03 int ii; // Local stack variable 04 ii = 2; 05 return &ii; 06 } 07 main() 08 { 09 int *ii; 10 ii = get_ii(); // After this call the stack is given up by the routine 11 ...

Help deciphering a few lines of assembly

I have found these few lines of assembly in ollydbg: MOV ECX,DWORD PTR DS:[xxxxxxxx] ; xxxxxxxx is an address MOV EDX,DWORD PTR DS:[ECX] MOV EAX,DWORD PTR DS:[EDX+116] CALL EAX Could someone step through and tell me what's happening here? ...

Why does a pointer's allocated memory persist after a function, but not an array?

So, I ask this question in the context of a basic text input function I see in a C++ book: char *getString() { char temp[80]; cin >> temp; char * pn = new char[strlen(temp + 1)]; strcpy(pn, temp); return pn; } So temp declares an array of 80 chars, an automatic variable whose memory will be freed once getString() r...

The order of data in memory

A few simple questions. const int gFirst; const int gSecond; struct Data { static int First; static int Second; int first; int second; }; Data data; Is it guaranteed that the following statements are true? 1) &gFirst < &gSecond 2) &Data::First < &Data::Second 3) &data.first < &data.second ...

pointers to pointers and pointer arrays

Hello, gcc 4.4.4 c89 I understand pointers ok. However, I am stepping up to pointer arrays and pointers to pointers. I have been messing around with this code snippet and have left comments of what I think I understand. Many thanks for any advice if my comments are correct with the line of code? void increment_ptr() { /* Static ...

Arrays of pointers in C

Hii , I have written the following code to improve it for the higher datastructures . #include<stdio.h> #include<stdlib.h> #include<malloc.h> int display(int *a , int *b , int *c) { a[0] = b; a[1] = c; printf("\n%d %d",a[0],a[1]); ------- point 1 printf("\n %d %d",*(a[0]),*(a[1])); ------- point 2 re...

Python: convert swig object...

I am using SWIG to create a Python wrapper around a piece of C++ code which returns an object like this: TH1F*GetHist(); (The class TH1F has not been written by me.) Now under Python this results in an <Swig Object of type 'TH1F *' at 0x12da820> My problem is that I would like to use methods of this object which SWIG does not know ...