3 ms·
I always think it is inappropriate to type declare like char* p1 in the first place. Yes, you want to be saying "I'm declaring an 8 bit integer pointer" but sin
by zanny 10y ago
I always think it is inappropriate to type declare like char* p1 in the first place. Yes, you want to be saying "I'm declaring an 8 bit integer pointer" but since in reality the pointer declaration is bound to the name in C, you should do it everywhere.
So I always do char \p1. Yes, for a non-C programmer its not as intuitive, but C isn't intuitive a lot of the time (cough, char p1[] what?). But you avoid making these mistakes altogether.
Note in function declarations I use char, because you cannot do statement expansion with a comma there, and because in headers the variable name is optional anyway.
- shmerl 10y agoYou mean char *p; ? I prefer to use char* p; as well as std::string& s; and etc. rather than attaching the type syntax to the name, since in essence that's part of the type. But yes, it's a mess that this inherited C logic doesn't treat it that way clearly. To avoid such mistakes, it's better not to use comma declarations altogether, you can perfectly avoid them. It's a good feeling when working with new languages like Rust which avoid such mess.
- zanny 10y agoYes, the banes of markdown reap their ugly head again. The point is, though, that while in a developers mental model you attach ref or ptr to the type, the language itself does not, and writing it out like it does can easily drive newer developers who do not understand the nuance to make hard to recognize mistakes as a result of it.