Hi
I am a noob in C programming and trying to learn. I came across some code that needs some explanation from someone who can C.
The program should malloc a big memory block and I should then use this memory block to manage objects with pointers.
Code:
struct list_el {
int id;
struct list_el *prev;
struct list_el *next;
};
typedef struct list_el item;
int main(void)
{
void *myMemory = malloc(11111111111);
struct list_el* item = (struct list_el*)myMemory;
//Instead of using malloc when creating an object of this struct, can I do this:
int pos = add(pos) + item;
}
int add(int pos)
{
item *curr;
curr = pos + sizeof(struct list_el);
curr->id = 1;
return curr;
}
I have no clear understanding of what
Code:
struct list_el* item = (struct list_el*)myMemory;
do. Is my understanding of pointers and memory in this example wrong?