Reputation: 361
Is it considered good practice to use a transparent macro to abstract away implementation details? Like so:
#define valuePointer struct value*
struct list {
valuePointer* listData;
int length;
}
In my opinion, the macro makes the code cleaner and abstracts away the struct value** listData
that ought to go there. But it's kind of a useless macro; just directly meaning value*
. Is this ok?
Upvotes: 2
Views: 270
Reputation: 513
Not for this kind of usage, typedef was made to do what you just did, eg :
typedef struct value* valuePointer.
Defines are quite dangerous if you don't master them, but can be very efficient in some cases. In my opinion you should use it when dealing with different types needing same functions. For example if you wish to get the square of numbers :
#define SQUARE(i) ((i)*(i))
As you can see I added a lot of parentheses, because it really is dangerous.
I personally only see the needs of "abstracting" pointers when you have 3 layers or more of pointers, otherwise dereferencing twice is no big deal.
Upvotes: 1
Reputation: 25753
C has typedef for that
typedef struct value* valuePointer ;
Only hide the *
in the typedef if you have a good reason for it.
Upvotes: 4