C/C++ Declaration Syntax

The cluster discusses the confusing and ambiguous variable declaration syntax in C and C++, such as 'declaration follows usage,' pointer notation, and parsing issues like the most vexing parse, often comparing it to clearer alternatives in languages like Rust, Go, and others.

πŸ“‰ Falling 0.5x Programming Languages
3,100
Comments
20
Years Active
5
Top Authors
#6937
Topic ID

Activity Over Time

2007
2
2008
14
2009
24
2010
68
2011
94
2012
101
2013
145
2014
136
2015
152
2016
194
2017
132
2018
177
2019
262
2020
281
2021
216
2022
301
2023
286
2024
243
2025
257
2026
17

Keywords

OO PHP CSS HN VB OK ML POSIX CPL RDBMS int syntax foo variable type declaration foo bar operator bar declarations

Sample Comments

emmanueloga_ β€’ Apr 23, 2022 β€’ View on HN

what's stopping a new version of C from defining a better declaration syntax? (better = easier to read, write and understand)

pdntspa β€’ Jan 22, 2024 β€’ View on HN

It seems like you have the concept down pat. I don't see what's wrong with it?Like lots of languages use positionally-dependent symbols. In both Perl and VB various characters in the variable name implied things about its type. With C/C++ the position of * tells you lots of important things. How is this anything less than yet another random language quirk?

Kranar β€’ Nov 13, 2022 β€’ View on HN

The reason some languages use "let name: type" instead of "type name" is to eliminate various ambiguities, for example C++'s most vexing parse, or the classic C typedef ambiguity where a statement like "X * Y" is ambiguous because it could be the declaration of a variable Y whose type is "X*" where "X" is a typedef, or it could be the multiplication of a variable "X" with a variable "Y". There are many languages where the

tomjakubowski β€’ Sep 7, 2025 β€’ View on HN

A great example of "declaration follows use" outside of C syntax.

JoeAltmaier β€’ Jun 6, 2015 β€’ View on HN

Wait - are we talking C/C++ here? where a function call, a variable declaration, an expression cast all look identical?

lobster_johnson β€’ Mar 13, 2014 β€’ View on HN

Pointer semantics. The syntax in general bugs me. It's too close to C++ for my taste -- too many braces and brackets and sigils.

optymizer β€’ Aug 10, 2020 β€’ View on HN

I find your comment inflammatory and your zealousness amusing, but I'll bite and try to be reasonable by assuming you're willing to entertain another point of view.The whole "declaration follows usage" is just a bad tradeoff. It makes it easier to parse expressions. That's my understanding of why they did it. It makes it _objectively_ harder to read, because some declarations follow this easy pattern of "name on the right and type on the left", while for som

klysm β€’ Sep 18, 2025 β€’ View on HN

This is syntax sugar. Don’t conflate syntactic niceties with the semantic absurdity that C++ has.

jstimpfle β€’ May 17, 2024 β€’ View on HN

I never use comma, I always define one variable per line. Much easier to edit and read. However, the way it works is certainly not inconsistent.As to your other concerns, it makes perfect sense. int WHATEVER; read as "WHATEVER is an int" and you can work backwards from there. There is no more type syntax than that. The thing is, it's much easier to look at stuff this way since otherwise you'll have to shift back and forth between 2 different s

zanny β€’ Feb 1, 2016 β€’ View on HN

For someone who uses Reddit and HN too much I sure can forget about markdown.The function syntax C++ has seems more like a bandaid around the broken scoping rules inherited by C more than anything. If you were writing a replacement it seems like it would be one of your first considerations to make each statement scope limited to the scope of the declaration. I mean, that is what auto is effectively doing in C++ nowadays - you have to evaluate the whole statement to resolve what auto is suppos