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 ) )
The spacing is obviously dreadful; however, the result is what you'd expect, right? Given the following code, we can distinguish what happens in sizeof calls.
If I saw that line of code in a project I worked on, I'd assume it was a bug and talk to the developer who wrote it. If that dev told me it was not a bug, I'd ask him to add parentheses. If he didn't want to to that, well, then I'd kick him right in the fucking nuts.
It is one more example for the horrible syntax that C or C++ allow.
See also:
- C++ Pitfalls: http://www.horstmann.com/cpp/pitfalls.html - C++ FQA lite: http://yosefk.com/c++fqa/ - C++?? : A Critique of C++ (3rd Ed.): http://burks.bton.ac.uk/burks/pcinfo/progdocs/cppcrit/
(no subject)
Date: 2008-10-04 14:44 (UTC)sizeofis an undeclared variable, right?(no subject)
Date: 2008-10-04 15:14 (UTC)(no subject)
Date: 2008-10-04 15:56 (UTC)(no subject)
Date: 2008-10-04 16:06 (UTC)Is it just a spacing thing?
Date: 2008-10-04 16:11 (UTC)The spacing is obviously dreadful; however, the result is what you'd expect, right? Given the following code, we can distinguish what happens in
sizeofcalls.Once run (on a 32-bit machine), we get the output indicated by the
printfcalls.So, in the end, it's just a matter of knowing operators and precedence. If one does any C programming, this is always an important thing to pick up.
(no subject)
Date: 2008-10-04 16:29 (UTC)Another one...
Date: 2008-10-04 23:09 (UTC)while (i --> 0) // "Goes to" operator
{
foo(i);
}
(no subject)
Date: 2008-10-04 23:33 (UTC)(no subject)
Date: 2008-10-05 02:20 (UTC)Yet another one...
Date: 2008-10-05 12:57 (UTC)while (true) {
...
if (...) true = 0;
...
}
My favourite
Date: 2008-10-05 16:05 (UTC)Horrible
Date: 2008-10-07 05:28 (UTC)See also:
- C++ Pitfalls: http://www.horstmann.com/cpp/pitfalls.html
- C++ FQA lite: http://yosefk.com/c++fqa/
- C++?? : A Critique of C++ (3rd Ed.): http://burks.bton.ac.uk/burks/pcinfo/progdocs/cppcrit/
Re: My favourite
Date: 2009-04-19 17:14 (UTC)Re: My favourite
Date: 2009-04-22 08:27 (UTC)