2004/09/16 17:35:28
I'm getting the compiler warning
Warning [2066] type qualifier mismatch in assignment
two places in my code. I want to learn why and how to do it right.

One is from something like this:

putrsUSART("mystring ");

This one is particularly confusing because this is exactly how the MPLAB C18 Compiler Libraries document gives the example for putrsUSART().

The other is from

(* ouside of main *)
char small_global_array[5];
(* inside main *)
strcpypgm2ram( small_global_array, "AB \0");

Is there something I should be doing differently?
2004/09/16 20:57:59
The compiler libraries are built with the large memory model (far rom pointers) while the compiler uses the near memory model (near rom pointers) by default, unless you compile with -ml. The compiler is complaining that you're passing a 16-bit pointer to a string constant to a function that expects a 24-bit pointer. The compiler knows how to perform that conversion, so the code will work correctly even with the warning. Most any random char* cast applied to the string literal will suppress the warning while still generating correct code. The correct cast is (const rom far char *), but incorrect casts like (char *) will work, and even meaningless casts like (near far rom rom rom char *) will work.
2004/09/16 22:35:51
I admit I am completely naïve, but why would the compilier libraries be built with the large memory model, which I think means you can access more than 64K of memory space, when there are only 9 PICs which have more than 64K but 243 PICs with less than 64K? I'm obviously missing some point here.
2004/09/16 22:56:56
I agree; you'd think appropriate libraries would be linked based on the memory model used in compilation. But you do have the option of rebuilding the libraries yourself with the small model.
2005/03/26 11:24:32
When the function accepts a far rom char * (such as the putsrsUSART function), the warning is "type qualifier mismatch in assignment". When the function accepts a far rom void * (such as the memcpypgm2ram function), the warning is "suspicious pointer conversion". The "suspicious pointer conversion" warning will also occur when mixing pointer types, such as passing an unsigned char * to a char *.
2005/06/22 11:23:23
RP Henry
Maybe not the right way, but (after fiddling with const rom far char * and char * casts) I just turned off the warning message with -nw=2066 added to the project/build options/project/MPLAB C18/Use alternate setttings box.
2005/06/22 11:56:35
Definitely not the right way, since it will suppress meaningful warnings elsewhere. This warning occurs in places other than just calls to string library functions, and it occurs in places where the code is actually incorrect. For example,
char *cptr;
rom char *rptr;
cptr = rptr;
generates the "type qualifier mismatch" warning, and the value assigned to cptr will not be valid.
2005/06/23 10:11:33
RP Henry:

I got rid of the error by using "(rom char*)" to cast, i.e.

printf((rom char*) "# Firmware Version: V%S #\R", GeneralStrings[1] );

I don't know if your situation allows you to do that but it seems like a simple solution if it does.
2005/06/23 10:29:48
RP Henry
I started doing that, experimenting with the results of different casts. However, most of the code in use now using printf and sprintf functions is for debug statements directed to a bit-banged serial port. Once the board is checked out, most of that code will be removed for the production version. The remaining printfs will be written using the const rom far char * cast, pointless as it may be.
2005/06/23 10:43:00
RP Henry
I understand why there is a type qualifier mismatch, but I don't understand why tha value assigned to cptr will not be valid.
© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account