Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilation Error in g++ 4.3.4 compiler

Tags:

c++

#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 ;
}

compiling on g++ 4.1.2 20070115 (SUSE 10): No issue

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

fileName : 9 :error:declaration of char* basename(const char*) throws different exception

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

Kindly tell me why this is happening , Is there is any Interface changed in g++ between these two release (if I remove inclusion of string.h then compilation success on both version of g++ ,Is any Interface change in string.h).

like image 588
yshrini Avatar asked Dec 27 '11 09:12

yshrini


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
like image 159
Yola Avatar answered Oct 04 '22 22:10

Yola


It seems the name basename already exists in string.h:

  • http://ideone.com/Q9xSw - gives error (as it is exactly your code).
  • http://ideone.com/s0HIX compiles fine if you comment #include <string.h>
like image 25
Nawaz Avatar answered Oct 04 '22 21:10

Nawaz