Skip to content

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

@chmullig

Description

@chmullig

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions