3 ms·
There is nothing incorrect about multiple declarations, but the syntax can become confusing when declaring pointers or arrays: char *s = "foo", *t = "bar";
by sltkr 6y ago
There is nothing incorrect about multiple declarations, but the syntax can become confusing when declaring pointers or arrays:
char *s = "foo", *t = "bar";
A beginner might forget to add the asterisk in `*t` (especially if the first declaration is written `char*` with no space on the left of the asterisk). Similarly with multiple types:
char *p = "foo", **q = &p, *z[2] = {"foo", "bar"}, *(*f)(const char*) = strdup;
This is correct and an intermediate C programmer won't have too much trouble parsing these, but in the interest of clarity, it makes sense to put each declaration on a separate line.
If you find yourself needing a lot of local variables, that's often a bad sign anyway, since it implies that the function has a lot of state to manage. In that case, you might want to rethink your implementation to make it less complex, or restructure the code to make it more managable.