Elektrine lite

← Feed

@FiskFisk33@startrek.website

2026-09-21 04:27 UTC

question, why is a declaration not a statement?

Replies (3)

  • @sik0fewl@piefed.ca 2026-09-21 04:51

    Possibly because declarations were originally not statements in C? You could only declare variables at the start of a function, but not assign them to something at the same time. Not sure why it still wouldn’t be allowed, though, especially if an empty statement can be a statement.

    Open ##4790657

  • @gratux@lemmy.blahaj.zone 2026-09-21 04:53

    from what i could find “because it was designed that way” For what it’s worth, C23 has updated labels to allow being placed before declarations.

    Open ##4790659

  • @terranoid@lemmy.cafe 2026-09-21 05:08

    When it’s designed to be an expression while (int x = 1) { ... Modify x to eventually be zero... } That might make sense even if it looks weird. Kinda like a for loop.

    Open ##4790688