Implicit declaration of function ...???

This is a discussion on Implicit declaration of function ...??? within the C Programming forums, part of the General Programming Boards category; Hi, I keep getting the warning of: Code: Implicit declaration of funciton getline() whenever i use getline() function What does ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    13

    Implicit declaration of function ...???

    Hi,
    I keep getting the warning of:
    Code:
     Implicit declaration of funciton getline()
    whenever i use getline() function

    What does this warning mean actually ?
    Is this a serious warning, or just ignorable.

    Cheer!!

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    getline() is c++ not C. There is no standard C getline() function.

  3. #3
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    getline() is also a GNU provided extension available under #include <stdio.h>. It will not appear if you use the -ansi flag, because the -ansi flag excludes all GNU extensions. It's not part of standard C, as Ancient Dragon said.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    replace getline() with fgets() and your program will (maybe) work.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,289
    What's happening is that you have tried to use a function called getline() that hasn't been declared anywhere (eg in a header file) and the compiler takes your attempt to call it as an implicit declaration.

    As other have sort of said, your real problem is probably that you're calling a function that doesn't exist and you need to work out what function you really intend to call. If the function is one you actually know you're trying to call, find the corresponding header file and #include it.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    $ grep -n getline /usr/include/*.h


    If you're trying to use the C++ getline, then you need <iosteam> etc.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    Sorry if I am a topic digging here, but I came across this thread while searching for the answer for exactly this problem and I noticed noone here gave the right answer.

    The answer turned out pretty simple:
    getline() IS a valid C function which is defined in stdio.h. As some people rightfully suggested it is not a function that is defined in the ANSI standard, but it is a GNU extension. In order to correctly include these extensions you have to add a define:
    Code:
    #define _GNU_SOURCE
    #include <stdio.h>
    
    /* functions like getline() and getdelim() should be defined now */
    Ofcourse this only works if you are actually using glibc (e.g. on Linux or cygwin).
    Hope this clarifies the issue.
    -- LT

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,289
    Quote Originally Posted by Lord Thunder
    Sorry if I am a topic digging here, but I came across this thread while searching for the answer for exactly this problem and I noticed noone here gave the right answer.
    Depends on your perspective. I consider your post to be incorrect and misleading, as you make some statements early on which are compiler/library specific but you state them as generalities. Yes you correct them later, sort of, but the information you give is not generally true.
    Quote Originally Posted by Lord Thunder
    The answer turned out pretty simple:
    getline() IS a valid C function which is defined in stdio.h.
    No. The functions that are declared in <stdio.h> are specified in the ISO C standard. They are not required to be defined in stdio.h.

    Reliance on stdio.h declaring any function that is not specified in the C standard is invalid, unless you are prepared to constrain yourself to only one compiler and it's library (and possibly to a particular version of that compiler and library).
    Quote Originally Posted by Lord Thunder
    As some people rightfully suggested it is not a function that is defined in the ANSI standard, but it is a GNU extension.
    Exactly my point. There are a few commonly used compilers that are produced by vendors not associated with GNU. Most of those compilers do not support GNU extensions and are not bunded with glibc.
    Quote Originally Posted by Lord Thunder
    In order to correctly include these extensions you have to add a define:
    Code:
    #define _GNU_SOURCE
    #include <stdio.h>
    
    /* functions like getline() and getdelim() should be defined now */
    Ofcourse this only works if you are actually using glibc (e.g. on Linux or cygwin).
    Sort of. glibc, in practical terms, often relies on using a correct version of gcc (the GNU compiler collection). Several versions of glibc only work with particular versions of gcc. This is the reason that the gnu compiler and glibc are often bundled together, particularly with recent versions. Both the gnu compiler and library are supported on more systems than linux; cygwin is just one of several windows ports.

  9. #9
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Quote Originally Posted by Lord Thunder
    Sorry if I am a topic digging here, but I came across this thread while searching for the answer for exactly this problem and I noticed noone here gave the right answer.

    The answer turned out pretty simple:
    getline() IS a valid C function which is defined in stdio.h. As some people rightfully suggested it is not a function that is defined in the ANSI standard, but it is a GNU extension. In order to correctly include these extensions you have to add a define:
    Code:
    #define _GNU_SOURCE
    #include <stdio.h>
    
    /* functions like getline() and getdelim() should be defined now */
    Ofcourse this only works if you are actually using glibc (e.g. on Linux or cygwin).
    Hope this clarifies the issue.
    -- LT

    Why is it exactly that you are dredging up a 7 month old thread? Was the urge so strong to blabber that you could not resist? Give me a break.

    Forum Guidelines. Read before posting:

    5. Don't bump threads. (Bumping: posting messages on threads to move them up the list or to post on a thread that has been inactive for two weeks or longer).
    Any questions?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Replies: 15
    Last Post: 11-11-2007, 09:40 AM
  3. Implicit declaration of function : wait()
    By husust in forum C Programming
    Replies: 2
    Last Post: 02-06-2006, 08:35 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21