2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-27 15:18:06 +00:00

util: New macro CONST_CAST.

Casts are sometimes necessary.  One common reason that they are necessary
is for discarding a "const" qualifier.  However, this can impede
maintenance: if the type of the expression being cast changes, then the
presence of the cast can hide a necessary change in the code that does the
cast.  Using CONST_CAST, instead of a bare cast, makes these changes
visible.

Inspired by my own work elsewhere:
http://git.savannah.gnu.org/cgit/pspp.git/tree/src/libpspp/cast.h#n80

Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Ben Pfaff
2012-07-13 16:00:29 -07:00
parent e9c048007b
commit ebc56baa41
25 changed files with 69 additions and 55 deletions

View File

@@ -311,7 +311,7 @@ ds_cstr(struct ds *ds)
const char *
ds_cstr_ro(const struct ds *ds)
{
return ds_cstr((struct ds *) ds);
return ds_cstr(CONST_CAST(struct ds *, ds));
}
/* Returns a null-terminated string representing the current contents of 'ds',