Live data from Hacker News

Sizeof is surprisingly difficult to parse in C

sebsite.pw

11–15 of 15 posts

Re: Sizeof is surprisingly difficult to parse in C

#11
post #6

It's a unary operator, kind of like ~ or !, which can apply to parenthesis (), until it meets a type, then the parenthesis are mandatory: int x; sizeof x; // okay sizeof (x); // okay sizeof int; // not okay sizeof (int); // okay It's a weird double rule to parse, but even worse, the strongest binding precedence typically doesn't like an alpha identifier at that point in the recursive descent, so you get weird rules l…

[deleted]

Re: Sizeof is surprisingly difficult to parse in C

#12
post #2

> (everything here also applies to c2y's newly introduced _Countof) Stop the press, they're adding what ? So I don't have to keep adding #define count_of(arr) (sizeof(arr) / sizeof(*arr)) to every codebase and living with its failure modes? I'm really loving C's character arc at the moment, where they keep going back to fix old problems instead of piling everything and the kitchen sink into the language.

Yeah, despite puritanical hand-wringing over C23, I do like both the discipline and the selectivity with WG14 has shows (and I say this as a card-carrying C++ hater). I do wish they will start looking into proper arrays since there is already a syntax for this can can be augmented semantically: int func (int arg[static 5])

Can you explain what you mean exactly regarding this augmenting this syntax?

Re: Sizeof is surprisingly difficult to parse in C

#13
post #12

Earlier quoted context omitted.

Yeah, despite puritanical hand-wringing over C23, I do like both the discipline and the selectivity with WG14 has shows (and I say this as a card-carrying C++ hater). I do wish they will start looking into proper arrays since there is already a syntax for this can can be augmented semantically: int func (int arg[static 5])

Can you explain what you mean exactly regarding this augmenting this syntax?

I guess they are saying sizeof(...) should return the annotated static size rather than sizeof(int*) in this case

Re: Sizeof is surprisingly difficult to parse in C

#14
post #6

It's a unary operator, kind of like ~ or !, which can apply to parenthesis (), until it meets a type, then the parenthesis are mandatory: int x; sizeof x; // okay sizeof (x); // okay sizeof int; // not okay sizeof (int); // okay It's a weird double rule to parse, but even worse, the strongest binding precedence typically doesn't like an alpha identifier at that point in the recursive descent, so you get weird rules l…

Ive actually toyed with the idea of having @ as a pointer dereference. It seems to make sense: you want to know what is at the address stored in p.

Re: Sizeof is surprisingly difficult to parse in C

#15
post #2

> (everything here also applies to c2y's newly introduced _Countof) Stop the press, they're adding what ? So I don't have to keep adding #define count_of(arr) (sizeof(arr) / sizeof(*arr)) to every codebase and living with its failure modes? I'm really loving C's character arc at the moment, where they keep going back to fix old problems instead of piling everything and the kitchen sink into the language.

If only they actually fixed arrays and strings properly.

C23 and C2y have plenty of kitchen sink features.

Post reply on HN