fmemopen:赋值从整数中生成没有强制转换的指针 [英] fmemopen: assignment makes pointer from integer without a cast
问题描述
以下if条件
if((stream = fmemopen((void *)str,strlen(str)," r"))== NULL){
// ...
}
给我一个警告:赋值使整数指针没有
cast
但是只有当我用gcc编译它时。使用g ++,它很好。为什么
警告会出现?如何摆脱它(使用gcc)?
我用gcc 3.2.2和3.3尝试过它。 1并得到相同的警告
次。
谢谢!
Markus
PS:这是我正在尝试的程序的迷你版本
#include< stdio.h>
#include< string.h>
int main(){
char ch;
FILE * stream;
char * str =" ; test" ;;
if((stream = fmemopen((void *)str,strlen(str)," r"))== NULL){
fprintf (stderr,无法打开流到字符串''%s''\ nn,str);
}
while((ch = fgetc(stream) )!= EOF)
printf(" Got%c\ nn,ch);
fclose(stream);
return 0;
}
Markus Dehmann写道:以下条件
if((stre am = fmemopen((void *)str,strlen(str)," r"))== NULL){
// ...
}
给我一个警告:赋值从没有
强制转换的整数生成指针
由于没有fmem *函数作为标准C甚至C ++的一部分存在,你需要询问
在你的
实现的新闻组,邮件列表或技术支持中...
但只有当我用gcc编译它时。使用g ++,它很好。为什么会出现
警告,如何摆脱它(使用gcc)?
....并且当前的gcc实现在没有任何
fmem *函数的情况下作为提供的库的一部分提供。
>
看来你没有为你的函数包含适当的原型
。如果您已经将gcc调用为c89或c99兼容的
编译器,那么可以确定您包含的标题是
#include< stdio.h>
# include< string.h>
没有可见的任何fmem *函数的原型。
Markus Dehmann写道:
以下if条件
if((stream = fmemopen((void *)str,strlen(str)," r")) == NULL){
// ...
}
给我一个警告:赋值从整数中生成指针,而不是演员
.... snip。 ..
#include< stdio.h>
#include< string.h>
int main(){
char ch;
FILE * stream;
char * str =" test";
if((stream = fmemopen((void *)str,strlen(str)," r"))== NULL){
fprintf(stderr,无法打开流到字符串''%s''\ nn,str);
}
while((ch = fgetc( stream))!= EOF)
printf(" Got%c\ n,ch);
fclose(stream);
return 0;
}
fmemopen没有这样的标准功能。即使那里有
而且你只是忽略了#include相应的
标题,并且该函数采用了void * first参数,你应该
不能投出任何东西。所以你的代码真的应该是:
#include< stdio.h>
#include< string.h>
#include" fmemopen.h"
int main(void){
char ch;
FILE * stream;
char * str =" test";
if(!(stream = fmemopen(str,strlen(str)," r")) ){
fprintf(stderr,无法打开流到字符串''%s''\ n,
str);
}
else {
while((ch = fgetc(stream))!= EOF)
printf(" Got%c\\ \\ n",ch);
fclose(stream);
}
返回0;
} <假设fmemopen.h声明:
FILE * fmemopen(void *,size_t,char *);
此外,名称以str开头。保留用于
实现。你应该改变这些。
-
查克F(cb********@yahoo.com)(cb **** ****@worldnet.att.net)
可用于咨询/临时嵌入式和系统。
< http://cbfalconer.home.att.net>使用worldnet地址!
" CBFalconer" < CB ******** @ yahoo.com>在消息新闻中写道:40 *************** @ yahoo.com ...Markus Dehmann写道:
[..]
假设fmemopen.h声明:
FILE * fmemopen(void *,size_t,char *);
此外,名称以str开头;保留用于
实现。你应该改变那些。
IIRC,限制不适用于局部变量。如果我理解错误,请
纠正我。
Vijay
-
Chuck F(cb * *******@yahoo.com)(cb********@worldnet.att.net)
可用于咨询/临时嵌入式和系统。
< http: //cbfalconer.home.att.net>使用worldnet地址!
The following if condition
if((stream = fmemopen((void*)str, strlen(str), "r")) == NULL){
// ...
}
gives me a warning: assignment makes pointer from integer without a
cast
But only when I compile it with gcc. With g++ it''s fine. Why does the
warning show up and how can I get rid of it (using gcc)?
I tried it with gcc 3.2.2 and 3.3.1 and got the same warnings both
times.
Thanks!
Markus
PS: Here is a mini version of a program I am trying
#include <stdio.h>
#include <string.h>
int main(){
char ch;
FILE *stream;
char *str = "test";
if((stream = fmemopen((void*)str, strlen(str), "r")) == NULL){
fprintf(stderr, "Cannot open stream to string ''%s''\n", str);
}
while ((ch = fgetc (stream)) != EOF)
printf ("Got %c\n", ch);
fclose (stream);
return 0;
}
Markus Dehmann wrote:The following if condition
if((stream = fmemopen((void*)str, strlen(str), "r")) == NULL){
// ...
}
gives me a warning: assignment makes pointer from integer without a
cast
Since no fmem* function exists as part of standard C or even C++, you
need to ask in a newsgroup, mailing list, or tech support for your
implementation...
But only when I compile it with gcc. With g++ it''s fine. Why does the
warning show up and how can I get rid of it (using gcc)?
.... and there are current gcc implementations delivered without any
fmem* functions as part of the supplied libraries.
It appears that you have not included the appropriate prototypes for
your function. If you have invoked gcc as a c89 or c99 compliant
compiler then it is certain that the headers you included
#include <stdio.h>
#include <string.h>
have no prototypes for any fmem* functions visible.
Markus Dehmann wrote:
The following if condition
if((stream = fmemopen((void*)str, strlen(str), "r")) == NULL){
// ...
}
gives me a warning: assignment makes pointer from integer without
a cast .... snip ...
#include <stdio.h>
#include <string.h>
int main(){
char ch;
FILE *stream;
char *str = "test";
if((stream = fmemopen((void*)str, strlen(str), "r")) == NULL){
fprintf(stderr, "Cannot open stream to string ''%s''\n", str);
}
while ((ch = fgetc (stream)) != EOF)
printf ("Got %c\n", ch);
fclose (stream);
return 0;
}
There is no such standard function as fmemopen. Even if there
were and you have simply neglected to #include the appropriate
header, and the function took a void* first parameter, you should
not be casting anything. So your code should really read:
#include <stdio.h>
#include <string.h>
#include "fmemopen.h"
int main(void) {
char ch;
FILE *stream;
char *str = "test";
if (!(stream = fmemopen(str, strlen(str), "r"))) {
fprintf(stderr, "Cannot open stream to string ''%s''\n",
str);
}
else {
while ((ch = fgetc(stream)) != EOF)
printf("Got %c\n", ch);
fclose(stream);
}
return 0;
}
assuming fmemopen.h declares:
FILE *fmemopen(void *, size_t, char *);
In addition, names begining with "str" are reserved for the
implementation. You should change those.
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
"CBFalconer" <cb********@yahoo.com> wrote in message news:40***************@yahoo.com...Markus Dehmann wrote: [..]
assuming fmemopen.h declares:
FILE *fmemopen(void *, size_t, char *);
In addition, names begining with "str" are reserved for the
implementation. You should change those.
IIRC, the restriction is not for the local variables. Please
correct me, if I understood it wrongly.
Vijay
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
这篇关于fmemopen:赋值从整数中生成没有强制转换的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!