Difference in performance for accessing structs vs basic variables

Marcus Clyne maccaday@gmail.com
Sat Aug 15 17:58:00 GMT 2009


Hi,

Am I right in saying that there is no difference in performance between 
accessing the fields of a struct vs individual variables when you're not 
using pointers to access either?

e.g.

typedef struct {
    char   *data;
    int        len;
} my_str_t;

my_str_t   str;

str.data = "hello world";
str.len = 11;

VS

char *data;
int len;

data = "hello world";
len = 11;


I am assuming that the 'exact' (that is relative in the stack) location 
of the str.len is used, rather than an offset from the beginning of the 
'str' variable, with the position of str.len calculated at runtime each 
time it's accessed.  Is this correct?

I'm not talking about having *str, only the case when you define it as 
'str'.  I know that usually an offset will be used there.

Thanks,

Marcus.



More information about the Gcc-help mailing list