FridgeFreezer

External array constant, defining & using

Discussion created by FridgeFreezer on Oct 20, 2010
Latest reply on Oct 28, 2010 by pgo

Using CW7.2 (EWL C) for ColdFire, target device is MCF52259

 

Following my previous issues with defining a const array

https://community.freescale.com/thread/67968

I have now got that working using C99 extensions, but CW is now throwing an error on compile:

 

I have a character map in an array of 256 chars, indexed by ASCII value:

const char charmap[256] = { [' '] = 0x00, ['0'] = 0x0A, ['1'] = 0x01,  ['2'] = 0x02... you get the idea!

 

If I declare & define the array in the top of the .c file it's being used in, CW is happy and compiles & runs:

 

So in "display.c" I have:

 

 

const char charmap[256] = { [' '] = 0x00, ['0'] = 0x0A, ['1'] = 0x01,  ['2'] = 0x02...void displaythings(char ch){    output = charmap[ch]; // Converts ASCII char to our charmap value    print(output);}

 

 

That will compile & run fine.

 

But if I move the array to a header file, it fails:

 

display.h:

 

const char charmap[256] = { [' '] = 0x00, ['0'] = 0x0A, ['1'] = 0x01,  ['2'] = 0x02...

 

 

display.c:

 

#include "display.h"
extern const char charmap[256];

void displaythings(char ch){    output = charmap[ch]; // Converts ASCII char to our charmap value    print(output);}

 

 

If I try to compile I then get the following errors:

Error: multiply defined: "charmap" in display.h line 10

Error: previously defined in display.h line 10

Error: previously defined in display.h line 10

Error: previously defined in display.h line 10

Error: previously defined in display.h line 10

Error: previously defined in display.h line 10

Error: previously defined in display.h line 10

Link failed.

 

It behaves the same if I declare the extern const within the function(s). Can anyone shed any light on this?

Outcomes