ELSEIF
Your brief EB
183 stories from 71 feeds 32 clusters Refreshed 9 minutes ago next pull 13:20

TECH Signal 182

sizeof is surprisingly difficult to parse in c

WHY IT MATTERS

Engineers building C parsers, linters, or static analysis tools must handle this edge case correctly; naive backtracking approaches fail when compound literals and postfix operators follow a parenthesized type name, and conflating cast-expression parsing with unary-expression parsing produces incorrect results for expressions like `sizeof(int)+1`.

Written by elseif from the cluster below · every claim links back to a source

The three things worth knowing

01

The operand of `sizeof` is either a unary expression or a parenthesized type name, and only type names require parentheses.

02

Compound literals such as `sizeof(int){0}` make parsing difficult because a parenthesized type name can be followed by a compound literal and then arbitrary postfix operators like `.x[0]()`.

03

Combining unary-expression and cast-expression parsing into a single function does not work because `sizeof(int)+1` must parse as addition, not as the size of a cast expression.

THE CLUSTER

Same story, 1 feed.

ORDERED BY FIRST SEEN
Lobsters sizeof is surprisingly difficult to parse in c Open ↗