diff options
author | Ben Pfaff <blp@nicira.com> | 2012-07-13 16:00:29 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2012-08-03 13:33:13 -0700 |
commit | ebc56baa41db060b8783051e67b6fcbc148ebd60 (patch) | |
tree | 6eccb5e9fe078abf361ed9bcc2d23f5a3ca79395 /lib/sset.h | |
parent | e9c048007b113fdf05ca3ccbfa25d01c24f1da43 (diff) |
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>
Diffstat (limited to 'lib/sset.h')
-rw-r--r-- | lib/sset.h | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Nicira, Inc. + * Copyright (c) 2011, 2012 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ #define SSET_H #include "hmap.h" +#include "util.h" #ifdef __cplusplus extern "C" { @@ -82,7 +83,7 @@ bool sset_equals(const struct sset *, const struct sset *); #define SSET_NODE_FROM_HMAP_NODE(HMAP_NODE) \ CONTAINER_OF(HMAP_NODE, struct sset_node, hmap_node) #define SSET_NAME_FROM_HMAP_NODE(HMAP_NODE) \ - ((const char *) (SSET_NODE_FROM_HMAP_NODE(HMAP_NODE)->name)) + (CONST_CAST(const char *, (SSET_NODE_FROM_HMAP_NODE(HMAP_NODE)->name))) #define SSET_NODE_FROM_NAME(NAME) CONTAINER_OF(NAME, struct sset_node, name) #define SSET_FIRST(SSET) SSET_NAME_FROM_HMAP_NODE(hmap_first(&(SSET)->map)) #define SSET_NEXT(SSET, NAME) \ |