Error in header files in C++

Lionel Flandrin simias.n at gmail.com
Wed Sep 20 07:22:10 CEST 2006


On 9/20/06, Peter M. Groen <pgroen at osdev.nl> wrote:
> This should be a hint ;)
>
> #ifdef __cplusplus
>
> Classes are ended with a semicolon. Or you'll discover some other compiler
> errors like : "double declaration of....." etc..

I know that's not the end of a class declaration, that's the end of

 #ifdef __cplusplus
 extern "C" {
 #endif

//C header file

 #ifdef __cplusplus
 } // no semicolon here
 #endif

It's just to tell compiler to use C-style object linkage when using
this header in C++
(to forbid C++ name mangling which would result in errors at link time)

You can check here:
http://en.wikipedia.org/wiki/Name_mangling
I quote:

Handling of C symbols when linking from C++

The job of the common C++ idiom:

#ifdef __cplusplus
extern "C" {
#endif
    /* ... */
#ifdef __cplusplus
}
#endif

end of quote

as you can see, no semicolon here
-- 
Lionel Flandrin

-- 
This is the libdvbpsi-devel mailing-list, see http://developers.videolan.org/
To unsubscribe, go to: http://developers.videolan.org/lists.html



More information about the libdvbpsi-devel mailing list