Dictionary generation breaks on const members

I am trying to get some “third party” / external library visible in ROOT.
The following “sapi.h” breaks ROOT 5 and 6 (“root [0] .L sapi.h++”): #ifndef SAPI_H_INCLUDED #define SAPI_H_INCLUDED #ifdef __cplusplus extern "C" { #endif typedef struct sapi { const int id; } sapi; #ifdef __cplusplus } #endif #endif /* SAPI_H_INCLUDED */ If I reduce “typedef struct sapi” to just “typedef struct” then ROOT 6 survives but ROOT 5 still breaks.

Hi Pepe,

We cannot create a dictionary for this class, due to its const member.

To simply inject it into the interpreter please use

root [0] #include “sapi.h”.

Cheers, Axel.

Thanks for your reply but it will not work.
Unfortunately, the original include file contains many such structures and their members are not sorted in decreasing order of size, so one really needs to “precompile” it (so that no padding problems appear).

Well, maybe I have found a “simple fix” which works in ROOT 5 and 6: #ifndef SAPI_H_INCLUDED #define SAPI_H_INCLUDED #ifdef __cplusplus extern "C" { #endif typedef struct sapi { const int id; #ifdef __cplusplus sapi() : id(0) {}; #endif } sapi; #ifdef __cplusplus } #endif #endif /* SAPI_H_INCLUDED */ Could some “C/C++ standard” experts have a look at it, please.

Hi Pepe,

Do you want to do I/O on those types, or do you only need them in the interpreter?

Cheers, Axel.

I don’t think I need any I/O for these structures (but I cannot be 100% sure of that).
These are some kind of unique “id” for some “*SolverParameters” structures (so it may be that later one will want to “save” such “parameters” to some ROOT file).

Why do you think it matters?

Hi Pepe,

For interpretation, #include is just fine. (And in ROOT 6, for I/O it might be fine, too.)

The I/O needs to default construct a sapi to the fill the right bytes into the object. But the default constructor is off:

$ clang++ -x c++ -std=c++11 -fsyntax-only sapi.h
sapi.h:14:15: error: call to implicitly-deleted default constructor of '::sapi' (aka 'sapi')
   return new ::sapi;
sapi.h:8:15: note: default constructor of 'sapi' is implicitly deleted because field 'id' of const-qualified type 'const int' would not be
    const int id;
1 error generated.

So you’ll have to provide one, I’m afraid, just like you suggested.

Cheers, Axel.