[cfe-dev] sizeof(sizeof(...))

Pierre Habouzit madcoder at debian.org
Fri Dec 14 16:27:01 PST 2007

On Fri, Dec 14, 2007 at 08:30:59PM +0000, Ted Kremenek wrote:
> Does anyone have any insights on the semantics of expressions of the  
> form sizeof(sizeof(...))?  For example, the following is legal code:
> int baz(int x) {
>   typedef int a[f()];
>   return sizeof (sizeof(a[bar(x)]));
>          + sizeof(sizeof(x));
> }

I don't get the reason why someone would do that, but afaict sizeof is a
size_t (not an unsigned int) so sizeof(sizeof(a[bar(x)])) is just
sizeof(size_t). I don't have my C norm at hand, but at least gcc
believes that sizeof "returns" a size_t since its printf format checker
complains if I use "%d" and definitely wants "%zd".

·O·  Pierre Habouzit
··O                                                madcoder at debian.org
OOO                                                http://www.madism.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20071215/c08a3ff0/attachment.sig>

More information about the cfe-dev mailing list