警告的含义 [英] Meaning of the warning

查看:79
本文介绍了警告的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我对代码有一个问题。

#include< stdio.h>

char * f1(void );

char * f1(无效)

{

char * abc =" Hello" ;;


返回abc;

}


int main(无效)

{

char * p;

p = f1();


printf("%s \ n",p);

返回0;

}

编译上面提到的程序如下所述我得到了

意思是

$ gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -

Wpointer-arith -Wbad-function-cast -Wmissing-prototypes -Wstrict-

原型-Wmissing-declarations -Winline -Wundef -Wnested-externs -

Wcast-qual -Wshadow -Wconversion -Wwrite-strings -ffloat-store -O2

jj。 c $ / $
jj.c:在函数`f1'':

jj.c:5:警告:初始化从指针中丢弃限定符

target类型


我有两个问题

1)警告的含义是什么?

2)返回本地指针值是否安全(即返回abc;)

正确吗?


我的理解是我们不应该返回本地

变量的地址。所以上面的代码可能总是没有工作。


问候,

Somenath

Hi All,
I have one question regarding the code.
#include<stdio.h>
char *f1(void);
char *f1(void)
{
char *abc ="Hello";

return abc;
}

int main(void )
{
char *p;
p = f1();

printf("%s\n", p);
return 0;
}
While compiling the above program as mentioned below I am getting the
meaning
$ gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -
Wpointer-arith -Wbad-function-cast -Wmissing-prototypes -Wstrict-
prototypes -Wmissing-declarations -Winline -Wundef -Wnested-externs -
Wcast-qual -Wshadow -Wconversion -Wwrite-strings -ffloat-store -O2
jj.c
jj.c: In function `f1'':
jj.c:5: warning: initialization discards qualifiers from pointer
target type

I have two question
1) What is the meaning of the warning ?
2) is it safe to return the local pointer value (i.e return abc ;) is
correct ?

My understanding is we should not return address of local
variable .So above code may not be working always .

Regards,
Somenath

推荐答案

gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -

Wpointer-arith -Wbad-function-cast -Wmissing-prototypes -Wstrict-

原型-Wmissing-declarations -Winline -Wundef -Wnested-externs -

Wcast-qual -Wshadow -Wconversion -Wwrite-strings -ffloat-store -O2

jj.c

jj.c:在函数`f1'':

jj.c:5:警告:初始化从指针中丢弃限定符

目标类型


我有两个问题

1)警告的含义是什么?

2)r是否安全eturn本地指针值(即返回abc;)是

正确吗?


我的理解是我们不应该返回本地地址

变量。以上代码可能无法正常工作。


问候,

Somenath
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -
Wpointer-arith -Wbad-function-cast -Wmissing-prototypes -Wstrict-
prototypes -Wmissing-declarations -Winline -Wundef -Wnested-externs -
Wcast-qual -Wshadow -Wconversion -Wwrite-strings -ffloat-store -O2
jj.c
jj.c: In function `f1'':
jj.c:5: warning: initialization discards qualifiers from pointer
target type

I have two question
1) What is the meaning of the warning ?
2) is it safe to return the local pointer value (i.e return abc ;) is
correct ?

My understanding is we should not return address of local
variable .So above code may not be working always .

Regards,
Somenath


somenath< so ********* @ gmail.comwrites:
somenath <so*********@gmail.comwrites:

#include< stdio.h>

char * f1(void);

char * f1(void)

{

char * abc =" Hello" ;;


返回abc;

}


int main(无效)

{

char * p;

p = f1();


printf("%s \ n",p);

返回0;

}


编译上面提到的程序如下所述我得到了

意思
#include<stdio.h>
char *f1(void);
char *f1(void)
{
char *abc ="Hello";

return abc;
}

int main(void )
{
char *p;
p = f1();

printf("%s\n", p);
return 0;
}
While compiling the above program as mentioned below I am getting the
meaning


gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -

Wpointer-arith -Wbad-functi on-cast -Wmissing-prototypes -Wstrict-

原型-Wmissing-declarations -Winline -Wundef -Wnested-externs -

Wcast-qual -Wshadow -Wconversion -Wwrite- strings -ffloat-store -O2

jj.c

jj.c:函数`f1'':

jj.c:5 :警告:初始化从指针中丢弃限定符

目标类型


我有两个问题

1)这是什么意思警告 ?
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -
Wpointer-arith -Wbad-function-cast -Wmissing-prototypes -Wstrict-
prototypes -Wmissing-declarations -Winline -Wundef -Wnested-externs -
Wcast-qual -Wshadow -Wconversion -Wwrite-strings -ffloat-store -O2
jj.c
jj.c: In function `f1'':
jj.c:5: warning: initialization discards qualifiers from pointer
target type

I have two question
1) What is the meaning of the warning ?



可能与char的签名和

签名的Hello有关吗? />

Asbj ?? rn

May it have anything to do with the signed-ness of char and the
signed-ness of "Hello"?

Asbj??rn


这篇关于警告的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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