gcc 4签名vs unsigned char [英] gcc 4 signed vs unsigned char

查看:61
本文介绍了gcc 4签名vs unsigned char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我刚刚切换到gcc 4并且遇到了一堆警告

我无法解决。例如:


#include< stdio.h>


int main()

{

签名char * p =" Hola" ;;


返回0;

}


如果我编译该文件,我得到:

kk.c:在函数''main'':

kk.c:5:警告:初始化中的指针目标签名不同


只有当我从声明中删除签名时,它才会编译而没有

错误。我如何使用签名或未签名的字符?


我正在使用gcc 4.0.1。问这个的原因是因为在一个

程序中我总是使用int8_t和u_int8_t值,而且他们两个

都是签名或未签名的,不是简单的'' char''变量。


提前致谢。

解决方案



ju********@gmail.com 写道:

你好,
我刚刚切换到gcc 4,我遇到了一堆警告,我无法解决。示例:

#include< stdio.h>

int main()
{
signed char * p =" Hola" ;;

返回0;
}
如果我编译该文件,我得到:
kk.c:在函数''main'':
kk.c:5:警告:初始化中的指针目标在签名方面有所不同

只有当我从声明中删除签名时才会编译,而不会出现
错误。我如何使用签名或未签名的字符?

我正在使用gcc 4.0.1。问这个的原因是因为在一个
程序中我总是使用int8_t和u_int8_t值,并且它们都是有符号或无符号的,不仅仅是''char''变量。

提前致谢。




in gcc 3.4。没关系!


ju ** ******@gmail.com 写道:

你好,我刚刚切换到gcc 4,我遇到了一堆警告
#include< stdio.h>

int main()
{
signed char * p =" Hola" ;;

返回0;
}
如果我编译该文件,我得到:
kk.c:在函数''main'':
kk.c:5:警告:初始化中的指针目标在签名方面有所不同

只有当我从声明中删除签名时才会编译,而不会出现
错误。我如何使用签名或未签名的字符?

我正在使用gcc 4.0.1。问这个的原因是因为在一个
程序中我总是使用int8_t和u_int8_t值,并且它们都是有符号或无符号的,不仅仅是''char''变量。



char类型 - 由于历史原因 - 与签名字符

和unsigned char不同,可能有效(签名,大小,范围)

其中一个。

所以,只有

char * p =" Hola";

是永远正确。

干杯

Michael

-

电子邮件:我的是/ at / gmx / dot / de address。


ju ****** **@gmail.com 写道:

我刚刚切换到gcc 4,我遇到了一堆警告,我无法修复。示例:

#include< stdio.h>

int main()
{
signed char * p =" Hola" ;;

返回0;
}
如果我编译该文件,我得到:
kk.c:在函数''main'':
kk.c:5:警告:初始化中的指针目标在签名方面有所不同

只有当我从声明中删除签名时才会编译,而不会出现
错误。我如何使用签名或未签名的字符?

我正在使用gcc 4.0.1。问这个的原因是因为在一个
程序中我总是使用int8_t和u_int8_t值,并且它们都是有符号或无符号的,不仅仅是''char''变量。



为什么要使用signed char或int8_t作为字符

string?正确的声明是


char * p =" Hola";


" Plain" char是来自signed char和unsigned

char的不同类型,尽管它与其中一个具有相同的表示。


然而,该警告具有误导性。初始化是非法的(

约束违规),但指针目标实际上并不相同

签名。我刚刚提交了一份错误报告;请参阅

< http://gcc.gnu.org/bugzilla/show_bug.cgi?id = 23087> ;.


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net/ ~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


Hello,
I''ve just switched to gcc 4 and I came across a bunch of warnings that
I can''t fix. Example:

#include <stdio.h>

int main()
{
signed char *p = "Hola";

return 0;
}

If I compile that file, I get:
kk.c: In function ''main'':
kk.c:5: warning: pointer targets in initialization differ in signedness

Only if I remove the signed from the declaration it compiles without
errors. How can I use the signed or unsigned char?

I''m using gcc 4.0.1. The reason for asking this is because in one
program I''m always using int8_t and u_int8_t values, and both of them
are signed or unsigned, no simply ''char'' variables.

Thanks in advance.

解决方案



ju********@gmail.com wrote:

Hello,
I''ve just switched to gcc 4 and I came across a bunch of warnings that
I can''t fix. Example:

#include <stdio.h>

int main()
{
signed char *p = "Hola";

return 0;
}

If I compile that file, I get:
kk.c: In function ''main'':
kk.c:5: warning: pointer targets in initialization differ in signedness

Only if I remove the signed from the declaration it compiles without
errors. How can I use the signed or unsigned char?

I''m using gcc 4.0.1. The reason for asking this is because in one
program I''m always using int8_t and u_int8_t values, and both of them
are signed or unsigned, no simply ''char'' variables.

Thanks in advance.



in gcc 3.4. it''s ok!


ju********@gmail.com wrote:

Hello,
I''ve just switched to gcc 4 and I came across a bunch of warnings that
I can''t fix. Example:

#include <stdio.h>

int main()
{
signed char *p = "Hola";

return 0;
}

If I compile that file, I get:
kk.c: In function ''main'':
kk.c:5: warning: pointer targets in initialization differ in signedness

Only if I remove the signed from the declaration it compiles without
errors. How can I use the signed or unsigned char?

I''m using gcc 4.0.1. The reason for asking this is because in one
program I''m always using int8_t and u_int8_t values, and both of them
are signed or unsigned, no simply ''char'' variables.



The type char is - for historical reasons - distinct from signed char
and unsigned char and may be effectively (signedness, size, range)
either the one or the other.
So, only
char *p = "Hola";
is always correct.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


ju********@gmail.com writes:

I''ve just switched to gcc 4 and I came across a bunch of warnings that
I can''t fix. Example:

#include <stdio.h>

int main()
{
signed char *p = "Hola";

return 0;
}

If I compile that file, I get:
kk.c: In function ''main'':
kk.c:5: warning: pointer targets in initialization differ in signedness

Only if I remove the signed from the declaration it compiles without
errors. How can I use the signed or unsigned char?

I''m using gcc 4.0.1. The reason for asking this is because in one
program I''m always using int8_t and u_int8_t values, and both of them
are signed or unsigned, no simply ''char'' variables.



Why would you want to use either signed char or int8_t for a character
string? The correct declaration is

char *p = "Hola";

"Plain" char is a distinct type from both signed char and unsigned
char, though it has the same representation as one of them.

However, the warning is misleading. The initialization is illegal (a
constraint violation), but the pointer targets don''t actually differ
in signedness. I''ve just submitted a bug report; see
<http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23087>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于gcc 4签名vs unsigned char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆