# XC8: .asm to C ( i.e. Lowering One's Expectations)

#### joeyd999

Joined Jun 6, 2011
4,626
Hey, @nsaspook, I'm working on a PIC project in C. I feel icky all over.

In any case, I've got this code to declare and initialize an array of strings:

C:
const char * messages[] =   {
"Line 1 Init msg",    //m_init1
"Line 2 Init msg ",   //m_init2
"                "    //m_blank
};
The code compiles and runs as expected, but I get this compiler warning:

./messages.h:33:: warning: (1478) initial value for "_messages" differs to that in ./messages.h:33
What the heck does this mean?

#### ApacheKid

Joined Jan 12, 2015
1,095
Hey, @nsaspook, I'm working on a PIC project in C. I feel icky all over.

In any case, I've got this code to declare and initialize an array of strings:

C:
const char * messages[] =   {
"Line 1 Init msg",    //m_init1
"Line 2 Init msg ",   //m_init2
"                "    //m_blank
};
The code compiles and runs as expected, but I get this compiler warning:

What the heck does this mean?
I'd need to see more of the code to suggest an explanation, but the initialization itself looks odd. I'd expect that be:

Code:
const char messages[] =
{
"Line 1 Init msg",    //m_init1
"Line 2 Init msg ",   //m_init2
"                "    //m_blank
};
I'm not saying your wrong, it just looks a little odd, also this likely isn't the cause of your message.

#### joeyd999

Joined Jun 6, 2011
4,626
I'd need to see more of the code to suggest an explanation, but the initialization itself looks odd. I'd expect that be:

Code:
const char messages[] =
{
"Line 1 Init msg",    //m_init1
"Line 2 Init msg ",   //m_init2
"                "    //m_blank
};
I'm not saying your wrong, it just looks a little odd, also this likely isn't the cause of your message.
Trying to make an array of strings, not an array of char.

#### ApacheKid

Joined Jan 12, 2015
1,095
Trying to make an array of strings, not an array of char.
OK yes, I see, you're right, that does create an array of three pointers (I was as seeing it as a single pointer to an array).

#### djsfantasi

Joined Apr 11, 2010
8,684
Trying to make an array of strings, not an array of char.
I didn’t think there was a string type in C? What do I know? Arduino C has a string type.

But, your definition is an array of pointers to arrays of char. The error message you received indicates to me that you have conflicting definitions. Since it isn’t obvious, I’d look for a #include of a file messages.h. If not in your main program, then possibly in an #include nested in a #include.

#### joeyd999

Joined Jun 6, 2011
4,626
I didn’t think there was a string type in C? What do I know? Arduino C has a string type.

But, your definition is an array of pointers to arrays of char. The error message you received indicates to me that you have conflicting definitions. Since it isn’t obvious, I’d look for a #include of a file messages.h. If not in your main program, then possibly in an #include nested in a #include.
In C, an array of char is a string.

According to the warning, the initial values defined on line 33 of messages.h conflict with those defined on line 33 of messages.h. Go figure.

There are no other declarations of messages.

#### ApacheKid

Joined Jan 12, 2015
1,095
In C, an array of char is a string.

According to the warning, the initial values defined on line 33 of messages.h conflict with those defined on line 33 of messages.h. Go figure.

There are no other declarations of messages.
You've only shared that small fragment of code, can you share all of it? Is this in Github by any chance?

#### joeyd999

Joined Jun 6, 2011
4,626
I made another array called xyz and got the same exact message. I know I have no other declaration of xyz anywhere!

And, the resulting output is exactly as I desire, except for the warning.

#### ApacheKid

Joined Jan 12, 2015
1,095
There is a problem, it seems the compiler thinks there are two places its being assigned. What happens if you temporarily remove the "const"?

#### nsaspook

Joined Aug 27, 2009
10,715
A few things to look for: https://www.microchip.com/forums/m876111.aspx
I recommend that you do not put initialised variable definitions in any header file.
I recommend that you do not put variable definitions of any sort in any header file.
I recommend that you put variable declarations in a header file. (A declaration probably starts with extern.)
I recommend that you put variable definitions in a source file which includes the header file.
https://www.gamedev.net/tutorials/_...mming/organizing-code-files-in-c-and-c-r1798/

#### ApacheKid

Joined Jan 12, 2015
1,095

#### joeyd999

Joined Jun 6, 2011
4,626
You've only shared that small fragment of code, can you share all of it? Is this in Github by any chance?
No. But it's just a .h file. And the error is the same whether or not the array is referenced.

In the end, the code works as expected.

#### joeyd999

Joined Jun 6, 2011
4,626
Nope. All other variable initializations work fine in the .h file.

The warning occurs whether or not the array is referenced in other files.

And -- save for the warning -- the code works as expected.

Of course I went the Google route prior to posting here. In fact, I did that first mostly because I'm ashamed at you guys knowing I'm writing embedded code in C. I didn't want you all to see me naked!

I specifically called you out because I figured that, as an embedded C vigilante, you'd know exactly what was going on and would have provided an exact -- and correct -- answer.

My esteemed vision of you has been shattered!

#### joeyd999

Joined Jun 6, 2011
4,626
Finally: for abstraction reasons (and you know how much I love abstraction!), I need the initialization in the header.

#### nsaspook

Joined Aug 27, 2009
10,715
Nope. All other variable initializations work fine in the .h file.

The warning occurs whether or not the array is referenced in other files.

And -- save for the warning -- the code works as expected.

Of course I went the Google route prior to posting here. In fact, I did that first mostly because I'm ashamed at you guys knowing I'm writing embedded code in C. I didn't want you all to see me naked!

I specifically called you out because I figured that, as an embedded C vigilante, you'd know exactly what was going on and would have provided an exact -- and correct -- answer.

My esteemed vision of you has been shattered!
I have a fix: #pragma warning disable xxxx

Yes, you will see it if you have a header file containing Definitions of objects, rather than just Declarations of those objects.

C Header files that contain object definitions can cause warnings...

Last edited:

#### joeyd999

Joined Jun 6, 2011
4,626
Btw,

const char xyz[] = "abc";

Compiles without warning.

#### joeyd999

Joined Jun 6, 2011
4,626

#### Tesla23

Joined May 10, 2009
524
I'm no expert, but this looks like the typical error you get when you put a definition in a header file. I suspect that each time you include the header file it reads the definition and allocates memory for the char arrays, so each source file that includes the header will give another allocation. The warning is that they have different addresses. As they are const it probably won't affect the program, but it will waste memory. As nsaspook says, restrict yourself to declarations in header files and definitions in source files, and being c you will probably have to use extern.

Last edited:

#### nsaspook

Joined Aug 27, 2009
10,715
I miss assembly.
I usually include at least two in most XC8 programs.

#pragma warning disable 520
#pragma warning disable 1498

#### ApacheKid

Joined Jan 12, 2015
1,095
Without seeing all source that's consumed by the compiler here, there's not an easy way to say if this is a compiler bug or a true error in the source code.