I am not an expert regarding pointers in C/C++ language and right now I have a program to understand with many complex variable structures.
The program developer created this struct:
1 2 3 4 5 6 7 8 9
typedefstruct
{
PNIO_UINT32 SlotNum; // related slot
PNIO_UINT32 SubslotNum; // related subslot
PNIO_UINT32 FrameLen; // length of the data (submodule-data length)
PNIO_UINT32 IoDatOffs; // offset of IO data object in IOCR-Data buffer
PNIO_UINT32 IopsOffs; // offset of IO provider state in IOCR-Data buffer
PNIO_VOID* pSubslot;
} PNIO_IODATA_OBJ_TYPE;
after that, I see this declaration:
PNIO_IODATA_OBJ_TYPE* pDatObj;
given the variable is a struct type pointer, is it correct to say pDatObj would point to a struct? The program uses a lot these pointers and I am a bit confused with how exactly they work. It happens inside a function where data are picked from memory and delivered by ethernet cable.
Worthy saying it is not a PC program, so any of these pointers must help me to find where to find the memory address I need. Data is previously written in memory before transmission.
There are no error in code, I need to learn how it work.
is it correct to say pDatObj would point to a struct
yes.
The program uses a lot these pointers and I am a bit confused with how exactly they work
difficult for us too to tell how they work. more code needed.
First see what the program do, see what all classes or struct's it has. See the broad flow of the code.. where it goes and where it ends. try to read any documentation if it has on what functions or classes do.
compile the code and run it and debug it. Debug slowly and dont try to finish everything quickly. Go on each line, see the value of each variable and how they are changing. This is the only way to understand the code.
pDatObj can either point to a block of allocated resources (of type PNIO_IODATA_OBJ_TYPE), or, it can point to another instance of PNIO_IODATA_OBJ_TYPE. Pointers themselves hold the address of the object it's pointing to.
A pointer basically points to another instance of the same type, or, alternatively, allocate a resource block that holds the same type.
Pointers work like this:
1 2 3 4 5 6
int *Pointer( NULL ); // NULL indicates that the pointer isn't pointing to anything.
int Object( 10 );
Pointer = &Object; // In English: Pointer = the object/data at the address of Object
*Pointer = 40; // In English: Assign the value of 40 to the address pointed to by Pointer.
Pointers aren't my strong pointer either so I try to come up with analogies for them.