4 ms·
I've encountered this problem in real code bases when you have a getter function for a complex data structure. You have to decide between: field *my_struct_
by colonwqbang 4y ago
I've encountered this problem in real code bases when you have a getter function for a complex data structure. You have to decide between:
field *my_struct_get_field(my_struct *s)
const field *my_struct_get_field(const my_struct *s)
In practice you will choose the first instance, so you simply won't use const where you could. Which is unfortunate.
It would be nice to have a shorthand for this. The nested macro shown in the paper looks like it can fix the problem, but is quite complicated. I would like something like:
autoconst field *my_struct_get_field(autoconst my_struct *s)
The returned pointer inherits the qualifiers of the argument. Inside the getter function the pointer is const, and there is only one implementation of the function.