简体   繁体   中英

conflicting types for getline function

I have a function for getline function in my code block.But while compiling the make file i get the following error:

cc -DMAIN   -c -o terp.o terp.c
terp.c:130:15: error: conflicting types for ‘getline’
In file included from terp.c:2:0:
/usr/include/stdio.h:675:20: note: previous declaration of ‘getline’ was here 
make: *** [terp.o] Error 1

The part terp.c around 130:

 PRIVATE char *getline()
 {
static int first_time_called=1;
if(!first_time_called)
    return 0;
first_time_called=0;
return Expr;
 }

There are at least three possible solutions.

  1. As getline() is not in standard c library, but in POSIX (and GLIBC), there could be switch to disable its extension (they enabled by default in GCC). Try compiling your source with command cc -DMAIN -std=c99 -c -o terp.o terp.c .

  2. If you need POSIX extensions, you have to rename your getline() function to something else.

  3. Remove #include <stdio.h> from your source, this error message will disappear. But you may become confused if POSIX's getline() is used in your source code, as it will be replaced by yours.

您需要为getline函数选择一个不同的名称,因为标准clib中已经有一个getline

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM