generic_iterators  1.0.0
Demonstration of implementing and using type safe generic iterators in pure, standard C
typeclass.h File Reference

Utilities to define a typeclass and its instance. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define typeclass(funcs)
 Define a typeclass with the given functions. More...
 
#define typeclass_instance(Typeclass)
 Define a typeclass instance for the given typeclass. More...
 

Detailed Description

Utilities to define a typeclass and its instance.

Macro Definition Documentation

◆ typeclass

#define typeclass (   funcs)
Value:
struct \
{ \
funcs; \
}

Define a typeclass with the given functions.

Example

typedef typeclass(char* (*show)(void* self)) Show; // Defines a typeclass and names it `Show`
#define typeclass(funcs)
Define a typeclass with the given functions.
Definition: typeclass.h:23
Parameters
funcsA semicolon separated list of typeclass functions.
Note
The functions usually take the self from the typeclass instance (and possibly more arguments).

◆ typeclass_instance

#define typeclass_instance (   Typeclass)
Value:
struct \
{ \
void* self; \
Typeclass const* tc; \
}

Define a typeclass instance for the given typeclass.

This just contains a void* self member and the typeclass itself.

Example

typedef typeclass(char* (*show)(void* self)) Show;
typedef typeclass_instance(Show) Showable; // Defines the typeclass instance for `Show` typeclass
#define typeclass_instance(Typeclass)
Define a typeclass instance for the given typeclass.
Definition: typeclass.h:43
Parameters
TypeclassThe semantic type (C type) of the typeclass defined with typeclass(funcs).