tags:

views:

67

answers:

1

Probably something stupid I'm missing but, why am I getting this warning?

static void foo(char *path) {
    char *bname;
    char *path2 = strdup(path);
    bname = basename(path2);

(line with basename() call): warning: assignment makes pointer from integer without a cast

Indeed, if I change to this, the warning goes away:

    bname = (char *)basename(path2);

man 3 basename tells me:

char *basename(char *path);

Both dirname() and basename() return pointers to null-terminated strings.

What gives?

+4  A: 

Negative. It works properly to me. Are you sure you included the correct header?

#include <string.h>
#include <libgen.h>

static void foo(char *path) {
    char *bname;
    char *path2 = strdup(path);
    bname = basename(path2);
}

Could you tell us more about your compiling environment?

Dacav
In C, if you don't have a prototype for a function (i.e. include the correct header), the compiler will assume that the function returns 'int'. It sounds like this is the OP's problem.
Roger Lipscombe
Roger, I believe you have the right answer. If you posted it as an answer and not a comment, I'd select yours as the right one. Thanks to both of you!
EBM