A dreadful thing

Saturday, October 4th, 2008 10:32
[personal profile] kpreid
some type *foo;
size_t count = ...;

...

foo = malloc(count * sizeof * foo);

(no subject)

Date: 2008-10-04 15:56 (UTC)
From: [identity profile] dougo.livejournal.com
But if it's followed by an asterisk, doesn't it parse as a variable? Or if it's a reserved word, shouldn't it just not parse at all?

(no subject)

Date: 2008-10-04 16:06 (UTC)
From: [identity profile] kpreid.livejournal.com
sizeof is a reserved word and so is always a prefix operator. Given that it's there, the next * is the prefix dereference operator. So it's identical to the normal ( count * sizeof ( * foo ) )

(no subject)

Date: 2008-10-04 16:29 (UTC)
From: [identity profile] dougo.livejournal.com
OH. Good lord. :(