function prototype for readline? - Minix

This is a discussion on function prototype for readline? - Minix ; I'm writing a small program and using the readline function from the libedit library (/usr/lib/i386/libedit.a) provided by editline. I cannot find the header file that has the prototype for readline in it. The function itself is in /usr/src/lib/editline/editline.c, and I ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: function prototype for readline?

  1. function prototype for readline?

    I'm writing a small program and using the readline function from the
    libedit library (/usr/lib/i386/libedit.a) provided by editline. I
    cannot find the header file that has the prototype for readline in
    it. The function itself is in /usr/src/lib/editline/editline.c, and I
    can link to the library by using -ledit. I ran the following in /usr/
    src/

    find . -name '*.h' -print | xargs grep 'readline'

    and found that there is a readline function prototyped in /usr/src/
    commands/ftp/ftp.h:

    _PROTOTYPE(int readline, (char *prompt, char *buff, int len));

    but this is not the function I want to use. The function prototype in
    ftp.h returns an integer whereas the one in editline.c returns a
    character pointer.

    char * readline (prompt)
    CONST char *prompt;
    { function body }

    When I compile my program I get the following warnings:

    # cc question.c -ledit
    "question.c", line 7: (warning) implicit declaration of function
    readline
    "question.c", line 7: (strict) illegal conversion of int to pointer.

    Below is my question.c source file:
    --------------------------------------------------
    #include

    int main (void) {
    const char *line;

    line = readline ("$ ");
    printf("original string: %s\n", line); /* this is line 7 */

    return 0;
    }
    -------------------------------------------------

    My program works how I expect it do, but I don't really understand the
    warnings.

    I think I understand the first warning, but am not sure. My program
    only includes which doesn't have a prototype for readline in
    it, nor do any of the headers that stdio.h includes have a prototype
    for it in them, so it gives a warning that the function hasn't been
    declared. When I compile with the '-wo' option, this warning goes
    away. I don't understand why that happens b/c shouldn't it give me a
    warning about using a function that hasn't been prototyped no matter
    what style of C I'm using? When I compile with '-D_POSIX_SOURCE', the
    first warning does not go away.

    I can't understand the second one. Why would it be an illegal
    conversion from int to pointer unless it was using the readline
    function from the ftp source? It seems as though it is using the
    prototype from ftp.h but actually executing the function compiled into
    libedit.a?

    I'm not very experience with C or pointers so maybe this is a simple
    question to clear up and I didn't really need to type all of that.
    Maybe I just can't find the correct header file to include?

  2. Re: function prototype for readline?

    Dear jbholman,

    > I can't understand the second one. Why would it be an illegal
    > conversion from int to pointer unless it was using the readline
    > function from the ftp source? It seems as though it is using the
    > prototype from ftp.h but actually executing the function compiled into
    > libedit.a?


    You are the one declaring the function.

    In C, using an undeclared function implicitly declares it, as the first
    warning correctly states. The compiler can only guess abou the return
    type, and its guess is that all implicitly declared functions return
    int. You are using this int as if it is a pointer, which causes the
    second warning.

    The solution is to simply declare the function explicitly yourself:

    -------------------------------------------------
    #include

    char *readline(const char *prompt);

    int main (void) {
    const char *line;

    line = readline ("$ ");
    printf("original string: %s\n", line); /* this is line 7 */

    return 0;
    }
    -------------------------------------------------

    --
    With kind regards,
    Erik van der Kouwe

  3. Re: function prototype for readline?

    > With kind regards,
    > Erik van der Kouwe


    Thanks!


  4. Re: function prototype for readline?

    "Erik van der Kouwe" few.vu.nl> escreveu:

    > In C, using an undeclared function implicitly declares it, as the first
    > warning correctly states.


    Afaik, not in C99.

    --
    João Jerónimo

    "Computer are composed of software, hardware, and other stuff terminated
    in "ware", like firmware, tupperware, (...)" - by JJ.

+ Reply to Thread