[redland-dev] Raptor2: Unnamed struct & Forward Declaration

Dave Beckett dave at dajobe.org
Thu May 22 16:30:30 EDT 2014


On Thu, 22 May 2014, Christian Waechter wrote:

> Hello Raptor2-users,
>
> we want to use raptor2 in our C++ library-project and are implementing a 
> class that uses raptor2 internally and hides its use to other 
> developers/users.
>
> Therefore we decided to use forward declarations to raptor2 structs (e.g. 
> raptor_term ) in our headers, such that other developers using our library do 
> no necessarily need to point to raptor2 headers as well.
> We only use the raptor2 headers in the implementation-files.
>
> No we encountered a problem:
> Unfortunately "raptor_term"  is an unnamed struct where a forward declaration 
> is not possible, at least to my knowledge.

raptor_term is (like the other datatypes) a C typedef struct.

So as I understand, you need something like this inside raptor2.h

struct raptor_term_t {
...
}
typedef struct raptor_term_t raptor_term;

so that in your C++ you can use:

struct raptor_term_t;


> We see possibilities to use void pointers and reinterpret_casts instead of 
> pointers to a raptor_term or maybe a solution similar to the one pointed out 
> here: http://stackoverflow.com/a/8833176
>
> Both solutions are not nice and I would like to change this to a more 
> safer/clearer version.
> Are there any other suggestions or ideas how to deal with this?
>
> And another question regarding the unnamed structs in raptor2: Is there any 
> chance that it will be changed to named structs in future releases of 
> raptor2? I think this might ease the use of raptor2 in c++ code, at least in 
> the described case and as far as I am aware of the possible solutions right 
> now.

Sure.  The struct names are not part of the API but they can be in the 
hears.

>
> I am looking forward to any comment or help on this issue.
>
> Best Regards,
> Christian Waechter

The best next step is for you to propose a change/patch or pull
request on the raptor2 github.  This change would be to src/raptor2.h.in

Do all the typedefs needs this change, or just the ones mentioned in an 
API call?

Dave



More information about the redland-dev mailing list