>Synopsis:      conflicting types for 'getline'
>Category:      library
>Environment:
        System      : OpenBSD 5.2
        Details     : OpenBSD 5.2 (GENERIC.MP) #339: Wed Aug  1 10:13:24 MDT 
2012
                         
dera...@i386.openbsd.org:/usr/src/sys/arch/i386/compile/GENERIC.MP

        Architecture: OpenBSD.i386
        Machine     : i386
>Description:
        The program on page 29 of K&R fails to compile with gcc -ansi,
        producing the error message

                test.c:4: error: conflicting types for 'getline'
                /usr/include/stdio.h:244: error: previous declaration of 
'getline' was here

        The problem is that the getline function has been recently
        introduced to OpenBSD's stdio.h header file.  See

                http://marc.info/?l=openbsd-cvs&m=133237357129322

        But the declaration of getline in this header violates the ISO
        C90 standard, since getline is not a reserved identifier in the
        standard and subclause 7.1.3 of the standard states that "No
        other identifiers are reserved".

>How-To-Repeat:
        Place the program on page 29 of K&R in a file named test.c.  Or
        alternatively, place the following program in test.c.

                #include <stdio.h>
                
                int getline();
                
                main()
                {
                 return getline();
                }
                
                int getline()
                {
                 return 0;
                }

        Then, compile this program using the command

                gcc -ansi test.c
 
>Fix:
        The -ansi option for gcc should hide the declaration of getline
        in stdio.h.

Reply via email to