J
jacob navia
One situation where macros are the only solution, and inline functions
just do not cut it is when you have several structures that share a
common field, and you want to access it without a function call.
For instance in a container library (strange, what a coincidence )
all the containers share the "count" field, that access the number of
elements in the container.
Here it would be impossible to use an inline function since all the
containers are different types. A macro is the only solution:
#define GetCount(container) (container->count)
This will work with all containers. Unless you use lcc-win and have
true generic functions (or use C++) the macro is the only really
portable solution.
just do not cut it is when you have several structures that share a
common field, and you want to access it without a function call.
For instance in a container library (strange, what a coincidence )
all the containers share the "count" field, that access the number of
elements in the container.
Here it would be impossible to use an inline function since all the
containers are different types. A macro is the only solution:
#define GetCount(container) (container->count)
This will work with all containers. Unless you use lcc-win and have
true generic functions (or use C++) the macro is the only really
portable solution.