Array-like variable format

Hey everyone, is there any way to ensure that variables declared in this format:
1
2
3
4
int a;
int b;
int c;
int d;
would be accessible with a pointer like this:
(&a)[someint]
Last edited on
1
2
3
4
5
6
7
struct fourInts
{
  int a;
  int b;
  int c;
  int d;
}
with suitable instructions to your compiler to remove padding.
I should've mentioned that the variables are in a class and I need them to be a direct member of the class. I'm just not sure how to be sure that the variables are next to each other in the memory.
1
2
3
4
5
6
7
class fourInts
{
  int a;
  int b;
  int c;
  int d;
};

with suitable instructions to your compiler to remove padding.

What exactly do you mean by "remove padding"?
Would this work even if multiple threads were creating a 'fourInts' at the same time?
When you create an instance of a struct or class, the member variables are all created next to each other in memory. However, the compiler will sometimes pad the member variables with gaps. You can insist that it does not do any padding, thus ensuring that the member variables are all next to each other. http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding

If multiple threads made fourInts, each fourInt would be somewhere in memory. They would not be intermixed.
Ok, thank you.
Topic archived. No new replies allowed.