We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
Can anyone tell me how to instruct Keil to compile char's as unsigned char's by default?
I know that there are some help topics on this issue, but they seem to be giving a precompiler directive to tell the compiler to always compile char's as signed char's....
Thanks! Eric
That is the default.
translation: "Can anyone tell me how to instruct Keil to abolish following the C standard"
fat chance
Anyhow most of us use something like U8 for unsigned char, so, if extensive typing is the problem, just include
#define U8 unsigned char
Erik
Thanks for the fast replies!
The problem that I am having is actually the warning: #167-D: argument of type "char *" is incompatible with parameter of type "Uchar *"
of the otherway around: #167-D: argument of type "Uchar *" is incompatible with parameter of type "char *"
Why am I getting these warnings if Uchar and char are the same thing?
Thanks, Eric
Uh... because they're not...?
How did you define Uchar, and did you use the above mentioned pragma to change the default type for char?
I'm sorry, I am importing code from a project developed on another platform and for some reason I was thinking that "Uchar" was defined in Keil's libraries, but it isn't.
Anyways, here is how I have Uchar defined:
typedef unsigned char Uchar;
There is no #pragma SCH in my code anywhere that I can tell. I have searched "Find in Files" for both 'SCH' and '#pragma SCH,' nothing came up.
(So, I am still confused why I am getting the previously mentioned errors?)
If you are importing code and want these warnings fixed quickly use:
--diag_suppress 167
in the misc controls under C/C++ of configure flash tools
The compiler is not considering char (that is unsigned by default) the same as unsigned char. It is considering them 2 different types that just happen to be the same.
U8 and/or u8 are defined in Keil, but guess what, they are not the same as char, they are the same as unsigned char (even though char is unsigned by default)
Okay, great, thanks!
So, when I receive a warning like this, I can ignore it and things should still function correctly?
Sure, have I ever steered you wrong?
(I have this warnig surpressed because I like to use u8's and chars without warnings.)
One more quick question, where do I put this diag_suppress line? is it a compiler directive and goes in a C file?
What's a negative A? Or negative '-'?
"Unsigned chars" make no sense. Unsigned 8-bit integers, yes, but not "chars".
Use char only, and always, when you mean human-readable characters alone or in strings. Use other typedefs for integer types.
Drew, I understand you Use char only, and always, when you mean human-readable characters alone or in strings. Use other typedefs for integer types. but do see a risk in your post being misinterpreted.
so,
TO PRESERVE DATA STORAGE USE (UNSIGNED) CHAR EVERY TIME IT WILL BE ENOUGH.
i.e.
Select Flash Select configure flash tools Select C++ add it to the line "misc controls"
It's quite delightful when the grossly opinionated show their ignorance with such panache.
Robert,
Thanks a lot for your help, that worked great.
Maybe not 'ignorance' but 'simplification'. Yes, there is a lot about guaranteeing sign extension and such, but nevertheless
The C standard states clearly that "signed char" is same as "char" and concluding from that that 'unsigned char' is different from 'char' does not take an Einstein.
now, explain this difference
120 1 unsigned char Usevenx = 0x74; 121 1 unsigned char Ueightx = 0x82; 122 1 char sevenx = 0x74; 123 1 char eightx = 0x82; 124 1 U8 helper; 125 1 126 1 if (Ueightx > Usevenx) 127 1 { 128 2 helper = 7; 129 2 } 130 1 if (eightx > sevenx) 131 1 { 132 2 helper = 8; 133 2 } 134 1 0000 750074 R MOV Usevenx,#074H ; SOURCE LINE # 121 0003 750082 R MOV Ueightx,#082H ; SOURCE LINE # 122 0006 750074 R MOV sevenx,#074H ; SOURCE LINE # 123 0009 750082 R MOV eightx,#082H ; SOURCE LINE # 126 000C E500 R MOV A,Ueightx 000E D3 SETB C 000F 9500 R SUBB A,Usevenx 0011 4003 JC ?C0018 ; SOURCE LINE # 127 ; SOURCE LINE # 128 0013 750007 R MOV helper,#07H ; SOURCE LINE # 129 0016 ?C0018: ; SOURCE LINE # 130 0016 D3 SETB C 0017 E500 R MOV A,sevenx 0019 6480 XRL A,#080H 001B F8 MOV R0,A 001C E500 R MOV A,eightx 001E 6480 XRL A,#080H 0020 98 SUBB A,R0 0021 4003 JC ?C0019 ; SOURCE LINE # 131 ; SOURCE LINE # 132 0023 750008 R MOV helper,#08H ; SOURCE LINE # 133 0026 ?C0019:
so "char' and 'unsigned char is the same???