Skip to content

Use opaque pointers for ctx parameters #2

@rfuest

Description

@rfuest

At the moment the ctx parameter in fstReader... and fstWriter... functions has the type void *, which effectively disables all type checking on that parameter. I had at least one instance during the refactoring of GTKWave's loaders where I accidentally mixed up something and the compiler wasn't able to detect the error because of the use of a void pointer.

I would suggest to use opaque pointers instead. fstapi.h would be changed to something like:

typedef struct fstWriterContext fstWriterContext;
typedef struct fstReaderContext fstReaderContext;

void fstWriterClose(fstWriterContext *ctx);
...

This allows the compiler to check that a fstWriterContext or fstReaderContext is passed without allowing external access to the fields inside the struct, because the full struct is only defined in fstapi.c.

@tbybell: I would like your feedback on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions