Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Thread Closed: Issue successfully resolved

???
02/01/05 16:27
Read: times


 
#86294 - lookup table and extern
Hello Everyone,

I'm trying to impliment some lookup tables in code space, with initialization done in a seperate file. I have the following as a representation of what I have working-

headerfile.h
code unsigned int x_data[10]={0,1,2,3,4,5,6,7,8,9};
code unsigned int y_data[10]={10,11,12,13,14,15,16,17,18,19};


mainfile.c
#include <headerfile.h>

extern code unsigned int x_data[10];
extern code unsigned int y_data[10];

main()
{
unsigned int data1,data2;
		
data1=x_data[3];//this reads a 3
data2=y_data[5];//this reads a 15
}

This code works as expected, the data is in code and I can access it in my main program. The following mainfile.c works the same

mainfile.c
#include <headerfile.h>
//this part remarked out
//extern code unsigned int x_data[10];
//extern code unsigned int y_data[10];

main()
{
unsigned int data1,data2;
		
data1=x_data[3];//this reads a 3
data2=y_data[5];//this reads a 15
}


My questions are
1) Do I need the second declaration of my code variables in the mainfile? It works as expected with out it. From what I read of extern usage it should.

2) If possible I'd like to groupt the two arrays into a structure and initialize them in the headerfile. I tried to group them together as a structure and was unable to make them compile. Has anyone done anything similar to this and do you have a better way of setting up lookup tables? The real application will have several and they will be a bit longer, but I have the code memory to spare for it(64K).

The chip is SILABS C8051F040.
I use Keil C51 compiler and tools

Thanks
Andy


List of 5 messages in thread
TopicAuthorDate
lookup table and extern            01/01/70 00:00      
   Completely wrong!            01/01/70 00:00      
      OK            01/01/70 00:00      
   The struct            01/01/70 00:00      
      Thanks            01/01/70 00:00      

Back to Subject List