struct pointer

struct Pool {
int items;
uthread_sem_t lock;
uthread_sem_t count_from_empty;
uthread_sem_t count_from_full;
};

struct Pool* createPool() {
struct Pool* pool = malloc (sizeof (struct Pool));
pool->lock = uthread_sem_create(1);
pool->count_from_empty = uthread_sem_create(0);
pool->count_from_full = uthread_sem_create(MAX_ITEMS);
pool->items = 0;
return pool;
}

Given this how can I get for example lock from struct pool instead of struct pool*?
If you have an object, you use the dot operator (.)
If you have a pointer, you use the arrow operator (->)

1
2
3
4
5
6
7
8
9
struct Pool { ... };


struct Pool obj;  // <- an object
obj.lock = whatever;  // <- access with the dot


struct Pool* ptr = /*point to something*/;  // <- a pointer
ptr->lock = whatever;  //<- access with the arrow 
Topic archived. No new replies allowed.