]> git.ozlabs.org Git - ccan/commitdiff
ptrint: ptr2int and int2ptr are constant functions
authorDavid Gibson <david@gibson.dropbear.id.au>
Sun, 25 Oct 2015 12:00:06 +0000 (23:00 +1100)
committerDavid Gibson <david@gibson.dropbear.id.au>
Sun, 25 Oct 2015 12:01:00 +0000 (23:01 +1100)
By construction these functions depend only on their arguments, so declare
them as CONST_FUNCTION using the helper from ccan/compiler.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/ptrint/_info
ccan/ptrint/ptrint.h

index 8135d1ee8ee4a90cbb94189f6f0f2fafc2dd9bcf..6300a9bca9e5ed04c7f96c396654db257bd8e096 100644 (file)
@@ -48,6 +48,7 @@ int main(int argc, char *argv[])
 
        if (strcmp(argv[1], "depends") == 0) {
                printf("ccan/build_assert\n");
+               printf("ccan/compiler\n");
                return 0;
        }
        if (strcmp(argv[1], "testdepends") == 0) {
index 992e4b18bead034afcd25a7a9b617c8f17bc1548..d8642e6fefc4f5c4df08d51889b68945b36df0eb 100644 (file)
@@ -7,6 +7,7 @@
 #include <stddef.h>
 
 #include <ccan/build_assert/build_assert.h>
+#include <ccan/compiler/compiler.h>
 
 /*
  * This is a deliberately incomplete type, because it should never be
@@ -15,7 +16,7 @@
  */
 typedef struct ptrint ptrint_t;
 
-static inline ptrdiff_t ptr2int(const ptrint_t *p)
+CONST_FUNCTION static inline ptrdiff_t ptr2int(const ptrint_t *p)
 {
        /*
         * ptrdiff_t is the right size by definition, but to avoid
@@ -26,7 +27,7 @@ static inline ptrdiff_t ptr2int(const ptrint_t *p)
        return (const char *)p - (const char *)NULL;
 }
 
-static inline ptrint_t *int2ptr(ptrdiff_t i)
+CONST_FUNCTION static inline ptrint_t *int2ptr(ptrdiff_t i)
 {
        return (ptrint_t *)((char *)NULL + i);
 }