Pointer as a Type or Different Roles of the Asterisk in Clang
Date: 12/2/2023 · Tags: #clang, #functional-programmingWhich style do you prefer to declare a variable in C?
int *name
int* name
Rasmus Andersson (@rsms) open a thread 1 in X to discuss
the history of the convention of put asterisk symbol (*
) (also known as unary
operator) as a pointer type attched to the name (style 1) rather than the type
(style 2).
Nowadays, after a few years of experience as a programmer, I prefer style 2. It's more practical and easier to read in the functional programming way.
There are also many quite interesting comments and supplementary materials in the thread about deferencing operator 234, historical choices 5 and personal flavor 6. Worth to dig in.
Only one critical warning to pick the second style
Avoid declaring more than one variable per statement! -- Phil Eaton (@eatonphil) 7
That means DO
int* foo;
int* bar;
and DO NOT
int* foo, bar;