Note that there are some explanatory texts on larger screens.

plurals
  1. POC dynamic array initialization problem
    text
    copied!<p>I'm having a problem initializing an array of structs in my C program. Here's the function where it gets initialized:</p> <pre><code>void InitializeBPStructures() { SatCounterTable = (struct SatCounterTableEntry *)malloc(sizeof(struct SatCounterTableEntry) * Counter_Count); } </code></pre> <p><code>Counter_Count</code> is an integer global variable and <code>SatCounterTable</code> is declared earlier in the C source file as </p> <pre><code>static struct SatCounterTableEntry* SatCounterTable; </code></pre> <p>and if it's relevant this is my <code>SatCounterTable struct</code></p> <pre><code>struct SatCounterTableEntry { enum SatCounter_State Predict_State; md_addr_t tag; }; </code></pre> <p><code>md_addr_t</code> is just a label for an <code>unsigned int</code> corresponding to a memory address</p> <p>The problem is that when I try and compile, I get the following error</p> <pre><code>sim-safe.c:129: error: expected expression before ‘=’ token </code></pre> <p>And the array initialization in my <code>IntitializeBPStructures()</code> is on line 129. I'm not sure why this line is a problem. Any ideas?</p> <p>EDIT:</p> <p>Here's some additional lines of code around the function</p> <pre><code> 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++; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload