Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
Disambiguation of sizeof

When using the sizeof I always enclose it in parentheses, as it's a bit easier for me to read, even if I can sometimes omit it, in the first case below

sizeof unary-expression
sizeof ( type-name )

My question is how does the parentheses disambiguate things to the compiler? What would be an example where something like:

sizeof char

Would be ambiguous to a compiler?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Accepting a typename after sizeof would not allow all types to be specified in an expression: pointer types (eg: sizeof char * 10) would create an ambiguity complicating the parse, which currently is quite simple.

over 4 years ago · Santiago Trujillo Report

0

If sizeof type-name were allowed, then sizeof char * + 3 could be either:

  • (sizeof (char *)) + 3, which is the size of a char * added to 3 or
  • (sizeof (char)) * (+ 3), which is the size of a char multiplied by + 3.

Both of those would be valid parsings and fully defined by the standard (aside from the implementation-defined size of the pointer). So accepting sizeof type-name creates an ambiguity not resolved by the grammar or semantics.

Earlier Example

If sizeof type-name were allowed, then sizeof char [x] could be either (sizeof (char)) [x] (which is a valid expression if x is a pointer or array; the subscript operator accepts index[array]) or sizeof (char [x]) (which is a valid expression if x is an integer; it is the size of an array of x elements of char). Further, the grammar would provide no way to distinguish these; both would be valid parsings. Semantic rules could distinguish them based on the type of x, but then you have to parse before you can evaluate the semantic rules and would need some way for the compiler to undo the parsing.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!