beejjorgensen/bgc

5.7: Missing "printf()" (and some parentheses)?

Closed this issue · 1 comments

The example program is written this way:

sizeof(int); // Returns size of an `int`
sizeof p     // p is type int*, so returns size of `int*`
sizeof *p    // *p is type int, so returns size of `int`

Shouldn't it use printf() instead, so that readers can observe themselves what is getting returned (especially those who copypaste and then troubleshoot)? And shouldn't sizeof() always accept arguments in parentheses?

printf("%zu\n", sizeof(int)); // Returns size of an `int`
printf("%zu\n", sizeof(p));   // p is type int*, so returns size of `int*`
printf("%zu\n", sizeof(*p));  // *p is type int, so returns size of `int`

So the parens are only necessary if you have a type in there, like int or float. If it's an expression, like x+12 or p then they're extraneous (just like they're extraneous in an expression like x = (y + z)).

In the existing code, I should be consistent with semicolons. And technically it "evaluates to", not "returns".

But should I printf()? Yeah, I think so. It'll be in the next release. Thanks!