I have a library 1-1.h.
#include <1-1.h>;
Which has a struct:
struct bucket { ... }
Unfortunately this library is 3-party and they have changed the struct bucket to bucket_t { ... } in 1.2. All my code uses bucket but I would also like it compatible with bucket_t.
Is it possible to:
#ifndef bucket
typedef bucket_t bucket;
#endif
(Code doesn't work but I would like to set bucket to bucket_t if it exists. Thanks.
One option is to add your own predefined symbol in your project or makefile that specifies which version you are using. Something like LIBRARY1_1 or LIBRARY1_2. If neither are defined report an error. You can do this by using your own include file like below.
If the header file is different for each version you use...
my1-1.h
#if defined( LIBRARY1_1 )
#include <1-1.h>
#elif defined( LIBRARY1_2 )
#include <1-2.h>
typedef bucket_t bucket
#else
#error Please define LIBRARY1_1 or LIBRARY1_2 before including this file
#endif
If the same filename is used for the header in each version...
my1-1.h
#include <1-1.h>
#if defined( LIBRARY1_1 )
#elif defined( LIBRARY1_2 )
typedef bucket_t bucket
#else
#error Please define LIBRARY1_1 or LIBRARY1_2 before including this file
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With