Problem with array of struct's

Code junkies hangout here

Moderators: ChriThor, LXF moderators

Problem with array of struct's

Postby stuarte9 » Tue Sep 09, 2014 4:55 pm

Hi all,

I'm currently developing a program to simulate a small microprocessor. When I compile the program using

gcc -ansi make_firmware.c -o make_firmware

the system reports the following solitary error:-

In file included from make_firmware.c:3:0:
make_firmware.h:53:14: error: variably modified ‘instr_table’ at file scope
INSTR_RECORD instr_table[max_records];

Now, my .h file contains the following:-
Code: Select all

typedef struct instrRecord
{
   MNEMONIC     command;
   ADDRESS_MODE addrMode;
   char *       cmdStr;
} INSTR_RECORD;


/* Maximum number of instruction records. */
const int max_records = 151;


/* Table of all assembly language instructions. */
INSTR_RECORD instr_table[max_records];                 /* line 53 of .h file */


The array instr_table has data inserted into its fields in the .c file.

Could someone please explain why this error was generated and possibly point me in the direction of a solution?

Thanks in advance for any help that you may be able to give with this.

Best regards,

Stuart
stuarte9
 
Posts: 65
Joined: Mon Mar 08, 2010 5:03 pm
Location: Scotland

Re: Problem with array of struct's

Postby shaddack » Wed Oct 08, 2014 5:27 pm

Hi

This post is a month old so I guess that you found the answer. But in case you haven't:

You can't declare variables in the header file as you have done with instr_table. That must go in the C file.

The header file shall only have definitions not declarations.

:)

Regards
Currently using openSuse 13.2
User avatar
shaddack
 
Posts: 75
Joined: Mon Mar 17, 2008 6:03 pm
Location: Gothenburg, Sweden

Re: Problem with array of struct's

Postby stuarte9 » Thu Oct 09, 2014 9:22 am

Good morning shaddack,

Thanks for the reply. Yes, I did manage to find an answer. However the explanation you have given is still informative, and obviously something I had overlooked or got a bit confused about.

Best regards,

Stuart
stuarte9
 
Posts: 65
Joined: Mon Mar 08, 2010 5:03 pm
Location: Scotland

Re: Problem with array of struct's

Postby shaddack » Thu Oct 09, 2014 6:28 pm

You're weicome! :)
Currently using openSuse 13.2
User avatar
shaddack
 
Posts: 75
Joined: Mon Mar 17, 2008 6:03 pm
Location: Gothenburg, Sweden


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests