I have the following code:
struct cache_t * /* pointer to cache created */
cache_create(char *name, /* name of the cache */
int nsets, /* total number of sets in cache */
int bsize, /* block (line) size of cache */
int balloc, /* allocate data space for blocks? */
int usize, /* size of user data to alloc w/blks */
int assoc, /* associativity of cache */
enum cache_policy policy, /* replacement policy w/in sets */
/* block access function, see description w/in struct cache def */
unsigned int (*blk_access_fn) (enum mem_cmd cmd,
md_addr_t baddr, int bsize,
struct cache_blk_t * blk,
tick_t now,
int context_id),
unsigned int hit_latency)
{ /* latency in cycles for a hit */
struct cache_t *cp;
struct cache_blk_t *blk;
int i, j, bindex;
----
----
---
cp->blk_access_fn = blk_access_fn;
----
---
I WANT TO PRINT context_id and baddr . HOW CAN I DO IT ?
I have tried typecasting and everything but it keeps giving me error:
symbol “context_id” is invalid in current context.
HELP WOULD BE APPRECIATED.
I think you misunderstand the
cache_createfunction. It doesn’t havecontext_idorbaddrparameters at all. What it does have as a parameter isblk_access_fnwhich is a function pointer. That function which is presumably called bycache_createand it would have those 2 variables as parameters.A way to better visualize this would be like so:
This code is identical in functionality to the code you posted. As you can see,
cache_createdoesn’t have the parameters you are looking for at all. You must pass a function with an appropriate prototype as theblk_access_fnparameter, and it will have them.