Using a structure definition in c -
i defined structures in c this:
struct cache_line{ char valid; int tag; int lru; }; struct cache_set{ struct cache_line *lines; }; struct cache{ struct cache_set *sets; }; after these structures definitions, define function:
void do_something(struct cache_set *a_cache_set, int number){ *a_cache_set.lines[next].tag = tag; *a_cache_set.lines[next].lru = *current_count; *a_cache_set.lines[next].valid = 1; } in main, define cache_set , do:
struct cache_set a_cache_set = my_cache.sets[setid]; int a_number = 10; do_something(&a_cache_set, a_number); however, when compiling, following error @ do_something definition (at
*a_cache_set.lines[next].tag = tag; *a_cache_set.lines[next].lru = *current_count; *a_cache_set.lines[next].valid = 1; ) :
error: request member ‘lines’ in not structure or union yet, explicitly declared a_cache_set cache set contains lines...
what wrong here?
this operator precedence issue.
*a_cache_set.lines[next].tag = tag; *a_cache_set.lines[next].lru = *current_count; *a_cache_set.lines[next].valid = 1; is equivalent to
*(a_cache_set.lines[next].tag) = tag; *(a_cache_set.lines[next].lru) = *current_count; *(a_cache_set.lines[next].valid) = 1; what need is:
(*a_cache_set).lines[next].tag = tag; (*a_cache_set).lines[next].lru = *current_count; (*a_cache_set).lines[next].valid = 1; or, better,
a_cache_set->lines[next].tag = tag; a_cache_set->lines[next].lru = *current_count; a_cache_set->lines[next].valid = 1;
Comments
Post a Comment