Question about linked lists

Lets say I have a linked list with a struct defined like this.

struct LList{
int data;
struct LList *NextList;
int data2;

When I allocate memory for a new entry to the list, and then put the pointer at correct spot in the previous entry, it unfortunately points to the start of the next structure. How, to I get it to instead point the the SAME spot in the next structure? Like it will be such that each entry in the list, will have its pointer pointing to the pointer item (the one called *NextList) in the next entry in the linked list?

Yes, I can simply add 4 to that pointer so it points 4 bytes ahead into the next structure, but then when ACCESSING it, in another part of the code, it will be treating the pointer as if it were pointing to the start of the next entry, when instead it's pointing 4 bytes ahead of that. How do I make it be a pointer with a true 4-byte offset into the next entry in the list, that will be correctly handled when reading back from that list?
the order of a struct is the order provided... if you want the pointer to be the zero offset, put it first.

however, the question, no offense, implies you don't understand something or are trying to do something really weird or getting to far down in the raw bytes.

the thing that is accessing the list should NOT have to know this level of detail about the memory alignment. It is either accessing it in a bad way, or you are not understanding something.

typical linked lists are just a chain of struct -> struct-> struct and the things inside the struct do not matter at all as far as alignment or ordering.
accessing it is just current->field ... regardless of where field lies in the block of memory.
I'm trying to make a struct similar to what's in here.

Look here
typedef struct _LDR_DATA_TABLE_ENTRY {
    PVOID Reserved1[2];
    LIST_ENTRY InMemoryOrderLinks;
    PVOID Reserved2[2];
    PVOID DllBase;
    PVOID EntryPoint;
    PVOID Reserved3;
    BYTE Reserved4[8];
    PVOID Reserved5[3];
    union {
        ULONG CheckSum;
        PVOID Reserved6;
    ULONG TimeDateStamp;

The pointers in the field called "LIST_ENTRY InMemoryOrderLinks;" do NOT point to the start of the next struct. If it did, it would point to the field "PVOID Reserved1[2];" in the next struct. What it does instead is it points to the field "LIST_ENTRY InMemoryOrderLinks;" in the next struct (that's 8 bytes into the struct, not the start of the struct). I can verify this by using a debugger to analyze any running EXE file and then looking at the correct block of system memory (where this struct resides).

I'm trying to do something similar with the struct that I'll be using as a linked-list in for my own C program.
Last edited on
I got nothing on how that could be happening.
Topic archived. No new replies allowed.