Wednesday, 15 July 2015

c - open_memstream warning "pointer from integer without a cast" -



c - open_memstream warning "pointer from integer without a cast" -

i'm writing c code embedded linux scheme using open_memstream , don't understand why getting compile warning: assignment makes pointer integer without cast

to create things simple, rather pasting code reproduced problem little illustration here:

#include <stdio.h> #include <stdlib.h> int main (void) { file *stream; char *buf; size_t len; off_t eob; stream = open_memstream (&buf, &len); if (stream == null) /* handle error */ ; fprintf (stream, "hello world"); fflush (stream); printf ("buf=%s, len=%zu\n", buf, len); eob = ftello(stream); fseeko (stream, 0, seek_set); fprintf (stream, "good-bye"); fseeko (stream, eob, seek_set); fclose (stream); printf ("buf=%s, len=%zu\n", buf, len); free (buf); homecoming 0; }

the code works, compiler complains line stream = open_memstream (&buf, &len);

what integer talking about? we're passing in pointer size_t required function prototype.

file *open_memstream(char **bufp, size_t *sizep);

is there problem code, or need take @ compiler? want rid of warning right way.

update:

using gcc 4.3.2, glibc 2.9

update 2:

tried following:

powerpc-860-linux-gnu-gcc -std=c99 -wall -d_xopen_source=700 -c source.c

result:

source.c: in function 'main': source.c:12: warning: implicit declaration of function 'open_memstream' source.c:12: warning: assignment makes pointer integer without cast

according this, seems _xopen_source=700 available since glibc 2.10.

since i'm using glibc 2.9, other alternatives have (other upgrading glibc)?

update 3:

adding next got rid of warning:

extern file *open_memstream(char **bufp, size_t *sizep);

is there wrong solution?

update 4:

this worked instead of extern:

powerpc-860-linux-gnu-gcc -std=c99 -wall -d_gnu_source -c ops_cmds.c

so according manpage, need utilize _gnu_source if glibc pre-2.10 (in case) , _xopen_source=700 if 2.10+

define:

#define _posix_c_source 200809l

or

#define _xopen_source 700

in source code before including stdio.h. or gcc can define , pass macro value source file -d option:

gcc -std=c99 -wall -d_xopen_source=700 -c source.c

open_memstream posix function , declaration not visible in programme without define.

c linux embedded

No comments:

Post a Comment