Do you realise that threading is basically the hardest topic that there is?!
You have how many years of C programming experience???
Will use array. This thread was informative very usefull nevertheless.
@imalc: Many years experience not. I am picking up my old C program that I was creating, it partially works but something is wrong with the semaphores, and mutex. Time to rap things up and finish things. If I were thinking like you said, that it's the hardest thing, well, where should I go in the future? Just stay in bed and think everything is difficult? God gave us a brain to use. So I intend to.
It might be a good way to say positive and encouraging things, instead of saying: no it's too difficult, etc.
Personalities are shaped with what you say to others. Every word has a positive or negavtive charge to it.
Don't you agree? Now , let us write code iMalc!
A basic problem with the advice given is that layout of structs is implementation dependent. One consequence of this is that incrementing a pointer to one member is not guaranteed to give the address of the next.
While it is true that struct members will appear in order, there is nothing preventing a compiler from inserting padding between them. So, the output of this code is 100% compiler dependent. It can vary between compilers from different vendors. It can change when you update your compiler.Code:
struct X x;
int *p1 = &(x.a1);
int *p2 = p1 + 1;
if (p2 == &(x.a2))
printf("Did not work\n");
Thanks Grumpy, you mean this:
what is structure padding - C / C++
There are ways to calculate it if I recall it right. Thanks for bringing it up. I might have missed it and guess what's wrong...
Sure, there are ways to calculate what padding is between struct members. But doesn't having to do that work against your wish to easily iterate over members? Arrays have none of that sort of problem and, unlike structs, are meant to be iterated over.