SQLite Forum

Subclassing & private data
Login
From [this page](https://sqlite.org/vtab.html), we have this paragraph:

> Virtual table implementations will normally subclass this structure to add additional private and implementation-specific fields.

and

> Once again, practical implementations will likely subclass this structure to add additional private fields.

Because I only know enough to shoot my feet in C, I'm wondering how that is going to work out. 

Looking at the samples, I see the typical pattern is to make the struct the first field of the actual struct, e.g.:

```
typedef struct JsonEachCursor JsonEachCursor;
struct JsonEachCursor {
  sqlite3_vtab_cursor base;  /* Base class - must be first */
  u32 iRowid;                /* The rowid */
  u32 iBegin;                /* The first node of the scan */
  u32 i;                     /* Index in sParse.aNode[] of current row */
  u32 iEnd;                  /* EOF when i equals or exceeds this value */
  u8 eType;                  /* Type of top-level element */
  u8 bRecursive;             /* True for json_tree().  False for json_each() */
  char *zJson;               /* Input JSON */
  char *zRoot;               /* Path by which to filter zJson */
  JsonParse sParse;          /* Parse of the input JSON */
};
```

However, I wonder how versioning is supposed to work. Some implementation will put in a size parameter to size the structure as to infer the version of the struct. Without that information, a new version of struct could potentially read private data from the old version and therefore garbage. But I don't see such member in sqlite's structure. Does the member `iVersion` of the struct `sqlite3_module` handle this? This statement implies it only applies to the module struct, not to the virtual table or cursor struct:

> The module structure also contains the iVersion field which defines the particular edition of the module table structure. Currently, iVersion is always 3 or less, but in future releases of SQLite the module structure definition might be extended with additional methods and in that case the maximum iVersion value will be increased.


I wanted to be sure that I'm following all the conventions that is expected as C seems to rely more on the conventions for it to work as opposed to other languages which may enforce the shape via its compiler. Thanks in advance!