Wow, I spend too much time to refactoring the code, but it not compile fine. :-( it's not easy to modify the problem with the typedef structs definition...or perhaps i'm wrong and it is more easy than I found.... could you check if it is more complicated? if not, I will forced to search to another library to be used on my project :-(
thanks for all toni
On Thu, Oct 27, 2011 at 06:25, Antonio Castellon - RAC < antonio.castellon.rac@gmail.com> wrote:
Dear Jan,
First of all, thanks for your answers. I don't want to evaluate if C is better than C++, on my particular case, I have need to integrate the libzdb into a framework of C++. Perhaps If you are interested (and if it is possible), I could modify the headers of this API according to C++ compatibility and send to the packet in order that you include (not substitute) this new header files as a complement for future users that has the same problem than me. Very thanks for your support, Best regards Toni
On Thu, Oct 27, 2011 at 03:10, Jan-Henrik Haukeland hauk@tildeslash.comwrote:
On Oct 26, 2011, at 5:56 PM, Antonio Castellon - RAC wrote:
Interesting. This has nothing to do with extern "C" which I mentioned earlier, though extern "C" should be added to libzdb headers if to be used from C++.
Out of curiosity I tested this and got the same error:
/usr/local/include/zdb/URL.h:55: error: conflicting declaration
‘typedef struct URL_T* URL_T’
/usr/local/include/zdb/URL.h:55: error: ‘struct URL_T’ has a previous
declaration as ‘struct URL_T’
It seems that the problem has to do with forward declaration and namespaces in C vs C++. In C, structs are in a separate namespace so it is perfectly legal to forward declare and typedef a struct to a type of the same name. That is;
typedef struct URL_T *URL_T;
But this does not work in C++ (as far as I understand, I'm no C++ guy though). In C++ a struct is (basically) the same as a class, so typedef *URL_T is in the same namespace as struct URL_T, hence the curious compiler error "‘struct URL_T’ has a previous declaration as ‘struct URL_T’". The "workaround" is simple; just give the two types different names. For instance lowercase the struct name:
typedef struct url_t *URL_T;
Since we use this typedef forward declaration idiom to declare all API objects in libzdb you would have to modify all the 5-6 API header files and corresponding source code where the type is declared, if you still want to use libzdb from C++. It is a question of modifying only 5 lines or so. Though I'm not inclined to do the change in the repository since this just demonstrated how C is superior to C++ (Obviously I'm a C guy :)
Best
-- To unsubscribe: http://www.tildeslash.com/mailman/listinfo/libzdb-general