diff options
author | 2004-10-18 16:35:54 -0700 | |
---|---|---|
committer | 2005-04-07 21:03:36 -0700 | |
commit | d16c7a0d4290dcc5a033710e6a5139031c88a323 (patch) | |
tree | 53288cba1e5b76525644d33402ddd7b39bff31b6 /inline.c | |
parent | Mark more identifiers reserved. (diff) | |
download | sparse-d16c7a0d4290dcc5a033710e6a5139031c88a323.tar.gz sparse-d16c7a0d4290dcc5a033710e6a5139031c88a323.tar.bz2 sparse-d16c7a0d4290dcc5a033710e6a5139031c88a323.zip |
Add __sizeof_ptr__ that looks at a pointer expression and
returns the size of the underlying object.
This is different from "sizeof(*expr)" for arrays, where
the array would degenerate to a pointer to one member, and
thus "sizeof(*expr)" gives the size of one entry in the
array.
Why do this? It's useful for things like
#define memset(a,b,c) ({ \
(void) __builtin_warning(__sizeof_ptr__(a) > 1, __sizeof_ptr__(a) != (c), "check memset size"); \
memset(a, b, c); })
where we really want to check the size of the object we're
doing the "memset()" on, but the regular sizeof() just doesn't
cut it.
Diffstat (limited to 'inline.c')
-rw-r--r-- | inline.c | 1 |
1 files changed, 1 insertions, 0 deletions
@@ -135,6 +135,7 @@ static struct expression * copy_expression(struct expression *expr) /* Cast/sizeof/__alignof__ */ case EXPR_CAST: case EXPR_SIZEOF: + case EXPR_PTRSIZEOF: case EXPR_ALIGNOF: { struct expression *cast = copy_expression(expr->cast_expression); if (cast == expr->cast_expression) |