pointers

Passing a pointer to an array in a different function in C

Ok, so I am trying to pass a pointer rgb that is initialized with memset to 0 and then looped through to place a 32 bit integer only in the bounds that I create with height and width input (h and w) as well as offset from the top left corner of the 2d array (x and y). after compiling, I seem to have the value with printf of the pointer ...

Should I explicitly cast malloc()'s return value?

I wanted to ask about the following case: char *temp; temp=malloc(10); Since the return type of malloc is void, will the pointer returned by the malloc be implicitly cast to char type before being assigned to temp? What does the standard say in this regard? If our pointer variable is some struct type for ex. struct node *temp; temp...

When is it preferable to store data members as references instead of pointers?

Let's say I have an object Employee_Storage that contains a database connection data member. Should this data member be stored as a pointer or as a reference? If I store it as a reference, I don't have to do any NULL checking. (Just how important is NULL checking anyway?) If I store it as a pointer, it's easier to setup E...

Pointers and online change in TwinCAT and CoDeSys

Are pointers safe against online change of running PLC program in TwinCAT 2.10 and in CoDeSys 2.3 on which the first one is based? What happens if memory block gets reallocated as part of online program change and there are pointers pointing to that memory block? ...

determine size of array if passed to function

Is it possible to determine the size of an array if it was passed to another function (size isn't passed)? The array is initialized like int array[] = { XXX } .. I understand that it's not possible to do sizeof since it will return the size of the pointer .. Reason I ask is because I need to run a for loop inside the other function wher...

using ref with class C#

I want to give a certain linked list to a class I am making. I want the class to write into that list (eg by .addLast()). Should I use the ref keyword for that? I am somewhat puzzled on where to use the ref and out keywords in C#, as all classes are allocated dynamically on the heap and we actually use pointers for most operations. Of ...

HWND abc = 0x100; This does not work, and I understand why. How to do it then?

Hello I have a HWND variable that I want to point to an hardcoded value, just for testing purposes. I guess that HWND is a typedef of (int*) so that is causing some kind of indirection. What should the correct code be like? ...

Volatile semantics in C99

I have an issue with some low level code I am writing, I need to use objects as volatile, but it is not necessarily so that I want the types to be declared as volatile (for reusability reasons). I can however define pointer to a qualified variant of a structure as detailed in the following segment. struct x { int bar; }; struct x foo...

Pointers in C# ?

In one C# maintenance project I came across following variable declaration: Int32* iProgressAddress; Is it pointer declaration in C#? I thought that there is no pointer concept in C#, what does that statement mean? ...

What portability issues are associated with byte-level access to pointers in C?

Purpose I am writing a small library for a larger project which supplies malloc/realloc/free wrapper-functions as well as a function which can tell you whether or not its parameter (of type void *) corresponds to live (not yet freed) memory allocated and managed by the library's wrapper-functions. Let's refer to this function as isgood_...

Does a pointer also have any address or memory allocation?

I would like to know if a pointer stores the address of any variable ... then from where do we get the pointer? What I asked was that if we are using pointer directly, then there must be a location from where we get this pointer? Please help, I'm gettin confused ... :(( ...

What exactly do pointers store? (C++)

I know that pointers store the address of the value that they point to, but if you display the value of a pointer directly to the screen, you get a hexadecimal number. If the number is exactly what the pointer stores, then when saying pA = pB; //both are pointers you're copying the address. Then wouldn't there be a bigger overhead t...

How to check if a pointer is valid?

I am well aware of the ugliness of this question, I'd still like to know if it's possible: When a program tries to read/write to an invalid pointer (NULL, unallocated block, etc') windows crashes the application with an access violation exception. The question is, is there a way to check wether this pointer will generate an exception b...

Allocate data through a function (ANSI C)

Hi all, I d love to know how I can allocate data through a function, and after the function is returned the data is still allocated. This is both for basic types (int, char**) and user defined types. Below are two snipsets of code. Both have the allocation within the function though after the return the allocation goes. int* nCheck = N...

Question about pointer in C?

int a[A][B]; int* p = a[i]; //i<A-1 then what's the actual operation of the sentence below? p++; p+=B; ...

ctypes in python, problem calling a function in a DLL

Hey! as you might have noticed I have an annoying issue with ctypes. I'm trying to communicate with an instrument and to do so I have to use ctypes to communicate with the DLL driver. so far I've managed to export the DLL by doing this: >>> from ctypes import * >>>maury = WinDLL( 'MLibTuners') >>> maury (WinDLL 'MlibTuners', handle 100...

Pass Pointer to an Array in Haskell to a C Function

I have the following C code: #include <sys/times.h> #include <time.h> float etime_( float *tarray ) { struct tms buf; times( &buf ); tarray[0] = 1.0 * buf.tms_utime / CLOCKS_PER_SEC; tarray[1] = 1.0 * buf.tms_stime / CLOCKS_PER_SEC; return tarray[0] + tarray[1]; } Trying to port this Fortran code to Haskell: ...

modifying a function parameter (a pointer) from within the application

This is a question based on C code for Win32. In one of my functions I have the following code: void SeparateStuff() { HGLOBAL hMem; IStream* pStream; Status result; unsigned char* pBytes; DWORD size; FILE* fp; if (hMem = GlobalAlloc(GMEM_MOVEABLE, 0)) { if (CreateStreamOnHGlobal(hMem, FALSE, &pStr...

(STL) Container of pointers

I'm having some trouble in declaring a STL Set of pointers to class instances. More specifically, I have this scenario: class SimulatedDiskFile { private: // ... public: // ... struct comparator { bool operator () (SimulatedDiskFile* const& file_1, SimulatedDiskFile* const& file_2) { return ((*file_1)->getF...

how important is having knowledge about pointers?

i am very weak in pointers , blame it on not having access to some good books .. while designing a compiler in c , how important is it to have a good knowledge about pointers?.. any good books?? ...