Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot interpret compiler warning

Tags:

c

My compiler (gcc) throws warnings (not errors!) on the line which declares fp:

int fd = open("filename.dat", O_RDONLY);
FILE* fp = fdopen(fd, "r"); // get a file pointer fp from the file descriptor fd

These are the warnings:

main.c: In function ‘main’:
main.c:606: warning: implicit declaration of function ‘fdopen’
main.c:606: warning: initialization makes pointer from integer without a cast

I do not understand these warnings since the return value of fopen is a FILE*. What is the mistake I am making here?

EDIT: I am including stdio.h (and I am also on Linux).

like image 601
pap42 Avatar asked Sep 02 '12 12:09

pap42


1 Answers

#define _XOPEN_SOURCE 600
#include <stdio.h>

This conforms perfectly with strict c99

gcc -std=c99 -pedantic -Wall -Wextra -Werror
like image 86
Arun Avatar answered Sep 30 '22 06:09

Arun