Oh, I just read the "From:" part of the message to know that.
Yeah, sometimes that works for me, too. ;-) I was just reading
on autopilot, and was jolted awake by the incredibly bad advice
Trollsdale was dishing out.
I disagree, and I think this is at best a matter of opinion. Since
there is nothing controvertial about what the compiler does (except
the issue of the "*" being associated with the variable/type being
declared instead of the defining type)
Funny, I'd say the opposite -- the association of the "*" is
absolutely, positively NON-controversial! It's dictated by an
international standard, for Pete's sake!
The controversial bit
of your post was where you seemed to advocate writing
char c, *p, q, *x;
or whatever it really was; I'm not going to take the time to look
back right now. I maintain that this is a Bad Idea.
Also, its not contrived -- go download Bstrlib and see for yourself.
I don't see any Bad Idea declarations in the CVS tree for bstrlib
at first glance. You do use 'int i,j;' and 'int i,v,n;' several times,
but I hope you can appreciate that declaring two or three closely
related objects of the same type on a single line is a far cry from
declaring four or five objects of different types on the same line!
As it happens, I *would* have re-written
bstring bBase64Encode (const bstring b) {
int i, c0, c1, c2, c3;
as
bstring bBase64Encode (bstring b)
{
int c0, c1, c2, c3;
int i;
which IMHO even without the (IMVHO) more-readable indentation makes
it more obvious that 'i' is unrelated to 'c0' etc. [And yes, IMO
it does *not* make more sense to use a four-element array here,
just in case anyone was going to piggy-back on this post. ;-) ]
But when I was talking about Bad Ideas, I was thinking of the common
newbie and ancient-scientific-code practice of writing
/* (e-mail address removed) */
int compare(FILE* , FILE* , long* , long* ), j;
/* (e-mail address removed) */
float sig_in[30], numerator[3], denominator[3], x[3], y[2], s_out[30];
which is just plain write-only code.
Most good compilers already help you with this potential problem, and
this is not a practical/useful suggestion for a large struct or ADT.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since initialization, is of arbitrary complexity, attempting to do so
solely within the declaration section is kind of futile in general.
If you remove the line I underscored above, your comment makes sense
and is true. I don't know why you added that second line, though --
it doesn't make any sense at all. Define variables when you need
them, and not [too far] before. As a corollary, if you find you need
an arbitrarily complex initialization scheme, it makes sense to put
that initialization in a function and write
struct myADT foo;
myADT_initialize(&foo, bar, baz, quux);
bstrlib does not seem at a glance to suffer from this problem, though.
-Arthur