Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sizeof confusion: drive home that it's done at compile time #40

Open
chmullig opened this issue May 11, 2014 · 1 comment
Open

sizeof confusion: drive home that it's done at compile time #40

chmullig opened this issue May 11, 2014 · 1 comment

Comments

@chmullig
Copy link
Member

So many people are super confused by sizeof, and use it where they shouldn't. for example, in place of strlen. It might help some to emphasize that sizeof is (normally 1) an operator evaluated at compile time, and becomes a constant. So it doesn't know. See K&R pgs 135, and to a lesser extent 203, for more.

  1. Note this breaks, slightly, with C99 variable length arrays where sizeof acts like an expression, not a constant. (invalid in the C++ spec as far as I can tell)
@hmontero1205
Copy link
Member

runtime vs. compile time kind of out of scope
instead, show diff between strlen and sizeof in same example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants