Andrew: Those tests are very helpful. I change my mind. I agree to keep CHAR8 definition without change.
Thanks Liming From: af...@apple.com [mailto:af...@apple.com] Sent: Wednesday, March 23, 2016 1:47 AM To: Gao, Liming <liming....@intel.com> Cc: Kinney, Michael D <michael.d.kin...@intel.com>; edk2-devel (edk2-devel@lists.01.org) <edk2-de...@ml01.01.org>; Rothman, Michael A <michael.a.roth...@intel.com>; Laszlo Ersek <ler...@redhat.com>; Leif Lindholm <leif.lindh...@linaro.org> Subject: Re: [edk2] signedness of CHAR8 > On Mar 21, 2016, at 10:23 PM, Gao, Liming wrote: > > Andrew: > Thanks for your point. I verify this change with VS2015 and GCC49 on IA32 > arch. There is no warning report. So, I think the compiler option is not > required for all tool chains and all archs. But, this is not true for CLANG. > It may not be true for ARM. So, I suggest we add option -funsigned-char for > every tool chain and every arch to ensure char is unsigned. For VS tool > chain, /J (Default char Type Is unsigned) option. can be used. And, we also > update CHAR8 definition with unsigned char to clearly follow UEFI spec. > Liming, It looks like clang warns if you assume a string literal has a specific sign. The -funsigned-char flag does not change this behavior. ~/work/Compiler>cat string.c unsigned char *a = "a test"; signed char *b = "b test"; char *c = "c test"; ~/work/Compiler>clang string.c -S -funsigned-char string.c:2:16: warning: initializing 'unsigned char *' with an expression of type 'char [7]' converts between pointers to integer types with different sign [-Wpointer-sign] unsigned char *a = "a test"; ^ ~~~~~~~~ string.c:3:16: warning: initializing 'signed char *' with an expression of type 'char [7]' converts between pointers to integer types with different sign [-Wpointer-sign] signed char *b = "b test"; ^ ~~~~~~~~ 2 warnings generated. ~/work/Compiler>clang string.c -S string.c:2:16: warning: initializing 'unsigned char *' with an expression of type 'char [7]' converts between pointers to integer types with different sign [-Wpointer-sign] unsigned char *a = "a test"; ^ ~~~~~~~~ string.c:3:16: warning: initializing 'signed char *' with an expression of type 'char [7]' converts between pointers to integer types with different sign [-Wpointer-sign] signed char *b = "b test"; ^ ~~~~~~~~ 2 warnings generated. ~/work/Compiler> It looks like clang's -Wpointer-sign will warn if you write code that assumes the sign of string literals. I assume this is to enforce portability. It looks like you need to cast between char * and (signed char *or unsigned char *) to make the compiler happy. If we try to force CHAR8 to be signed or unsigned explicitly (type unsigned char), then we will have to cast all string literals to (CHAR8 *) ~/work/Compiler>cat string.c unsigned char *a = (unsigned char *)"a test"; signed char *b = (signed char *)"b test"; char *c = "c test"; ~/work/Compiler>clang string.c -S -funsigned-char ~/work/Compiler>clang string.c -S I think this is why CHAR8 is defined as a char in all the processor bindings. Thanks, Andrew Fish > Thanks > Liming _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel