Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The arg is expanded twice but evaluated zero times, since sizeof gives the size of its argument type without executing anything.


countof(foo()) looks like foo() is only called once, but would actually be called twice. That's what GP is talking about, it's evaluated twice after the expansion when the code is actually running, not during the expansion.


Again no, foo isn't called at all since countof() only uses its argument in a sizeof expression.


It is not evaluated for regular arrays. It is evaluated for arrays with variable size, you need to be careful a bit. But this is rarely happens to be a problem.

The general rule for sizeof is to apply it only to variable names or directly to typenames.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: