Compilation error in g ++ 4.3.4 compiler

#include <iostream> 
#include <string.h>
char* basename(const char* filname);
int main()
{
    return 0;
}
char *basename(const char* filename)
{
    char* base = (char *)filename;
    return base ;
}

compilation on g ++ 4.1.2 20070115 (SUSE 10): No problem

compiling on g ++ 4.3.4 (SUSE 11) gives the following error

filename: 9: error: declaration char * basename (const char *) throws a different exception

fileName: 3: error: from previous declaration char * basename (const char *) throw ().

Tell me why this is happening. Is there any interface changed in g ++ between these two versions (if I remove the inclusion of string.h, then compilation success on both versions of g ++, is there any change in the interface in string.h).

+5
source share
2 answers

looks like basename already defined in string.h

# ifndef basename
/* Return the file name within directory of FILENAME.  We don't
   declare the function if the `basename' macro is available (defined
   in <libgen.h>) which makes the XPG version of this function
   available.  */
#  ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
extern "C++" char *basename (char *__filename)
     __THROW __asm ("basename") __nonnull ((1));
extern "C++" __const char *basename (__const char *__filename)
     __THROW __asm ("basename") __nonnull ((1));
#  else
extern char *basename (__const char *__filename) __THROW __nonnull ((1));
#  endif
# endif
+3
source

It seems the name basenamealready exists in string.h:

+1

All Articles