I'm having a problem initializing an array of structs in my C program. Here's the function where it gets initialized:
void InitializeBPStructures() {
SatCounterTable = (struct SatCounterTableEntry *)malloc(sizeof(struct SatCounterTableEntry) * Counter_Count);
}
Counter_Count is an integer global variable and SatCounterTable is declared earlier in the C source file as
static struct SatCounterTableEntry* SatCounterTable;
and if it's relevant this is my SatCounterTable struct
struct SatCounterTableEntry {
enum SatCounter_State Predict_State;
md_addr_t tag;
};
md_addr_t is just a label for an unsigned int corresponding to a memory address
The problem is that when I try and compile, I get the following error
sim-safe.c:129: error: expected expression before ‘=’ token
And the array initialization in my IntitializeBPStructures() is on line 129. I'm not sure why this line is a problem. Any ideas?
EDIT:
Here's some additional lines of code around the function
struct SatCounterTableEntry
{
enum SatCounter_State Predict_State;
md_addr_t tag;
};
/* simulated registers */
static struct regs_t regs;
/* simulated memory */
static struct mem_t *mem = NULL;
/* track number of refs */
static counter_t sim_num_refs = 0;
/* maximum number of inst's to execute */
static unsigned int max_insts;
static struct SatCounterTableEntry* SatCounterTable;
void InitializeBPStructures()
{
SatCounterTable = (struct SatCounterTableEntry *)malloc(sizeof(struct SatCounterTableEntry) * Counter_Count);
}
void BranchPredict(md_addr_t PC, md_addr_t nextPC, enum Branch_Result result)
{
if (result == N)
sim_num_mispred_static++;
if (result != (myrand() % 2))
sim_num_mispred_random++;
sim_num_br++;
}
SatCounterTable? It should be recognized by the compiler as an expression since it is a (global) variable.