S
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
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