Bill said:
Bill Pursell wrote:
Yevgen Muntyan wrote: [snip]
How about this: some people
use it successfully in some contexts, and it serves a good
purpose there? Those people are idiots, I guess, or not?
No, they are not idiots. I simply disagree
with them.
Disagree in what? You mean they should not do that regardless
of why they use the macro, regardless of the context?
I have never said that I disagree with
the claim the some people use it
successfully in some contexts. I do
disagree that any such context has
been given as an example in this
thread. I am not trying to enforce
my belief about the macro on anyone.
I originally joined this thread because
I had a simple example that I believe
demonstrates that the macro is NOT
robust, and I wanted to get the viewpoint
on that example from someone with a
differing opinion. I did this primarily
because I am giving the macro consideration,
a point which you seem to be missing.
One more
time: if one says "one must always use macro, macro is always
good", then he's wrong. But same thing is true about one who
says "the macro is never useful, one must not use it anywhere".
I said "the macro is silly". Don't put words
in my mouth. I didn't claim it is never
useful, nor do I claim that. I do think
it's silly, and I will probably never use
it myself. Nowhere have I claimed that
no one should ever use it.
If someone finds "sizeof *p" worse than "sizeof (TheType)"
then it's indeed worse, and he might not do what you think
is "right" (and here we go: context, experience, and so on).
I disagree. Someone might find readable
names worse than short names and might
like long functions and that person might
like to write 1000 line functions that begin
with: "int i,ii,j,jj,k,kk,ll,mm,m,n;".
But {his,her} perspective is amatuerish,
and the short functions with readable
names is not "indeed worse" simply because
of that person's perspective.
He didn't claim that, you ripped it out the context.
Yes, he did. I've gone back and looked at the
full context, and it certainly looks to me
that that is exactly what he claimed.
Nah, it's not just about me being stupid. It's about people who
call other's practices silly without *any* consideration.
Stop. Why do you continue to think that I've
given the macro no consideration? The entire
reason I joined this thread was precisely
because I was considering it. I tried
it out, found it to have a serious flaw,
and pretty much forgot about it. Then
I saw Paul's claim that the macro
catches all mismatches (and in going
back to look at the full context, it
still appears to me that that is exactly
what he claimed) and I posted an example
which I believe demonstrates a type
mismatch that the macro doesn't catch.
You think "Why would I use it? It's silly!" and you are
right. But you are *saying* "I disagree *you* should use it,
it's silly".
Again, I have not said that I think no one should
use it. Have I
written a plugin to your VCS which will
reject any code using such a macro? Have
I made a request to any compiler vendors
that they modify their preprocessors to
reject such a macro? Have I ever once said,
"No one should use it."? Have I ever said
"No one should use anything that I think
is silly"? No. I haven't, and I don't
think that. I do think this macro is
silly, though.
(You said you disagree with "those" people,
and I take it as you said they should not use such macros).
Well, you take it wrong. I'm not making
any claims about people at all. (Unlike
you, who seem to think that I'm closed
minded and unwilling to grow). I think
this macro is silly. I don't think
anything about the people who use it.
Perhaps a few more examples would serve.
I think it's silly that "int * x,y;"
declares a pointer and an integer rather
than 2 pointers. I think it's silly
that == has higher precedence that &.
I do not think that K&R are silly.
Quite the contrary.
I didn't try to convince you, and I am not claiming it'd
be useful for *you* anywhere. But you are saying it's not
useful for anybody (e.g. me), which is silly.
For (at least) the 3rd time, I am not saying
it's not useful for anybody. I am saying
that I don't see the use.
Then, using such a macro in a standalone program which
uses standard C + this macro is indeed strange. But it
may not be the case. Such macros are provided by many
libraries, and if you use such a library you get the
macro for free. *Then* you get little better type-checking
than with raw malloc.
And here I go again, giving the macro more
consideration. And here's why I think it's
silly: if you have a large code base in
which you've used this macro, and then
discover that you need to change a type
from int to long, you now get nice
compiler warning about type mismatches
in many places, and you have to go
make changes. If you have used
the malloc(sizeof *x) model, then you
don't get warnings and you don't
need to change the code base (because
the code still works).
*Then*, if you use the macro, you
use it a uniform way everywhere, not like your favorite
form which doesn't work in your example; the fact that
can be extremely important for some people. You know,
easier to read code, stuff like that.
Yes. I'm one of those people to whom it's
extremely important. I like clean, readable,
maintainable, robust, aesthetically appealing
code. My favorite form works perfectly correctly
in this example. It seems to me that
the problem here is your unwillingness to
give the standard form due consideration.
See, it's about
what one likes, not about what's "right".
Sometimes, what one likes is clearly not right.
That's not the case here, but there are definitely
times when there is a right way to do things.
If one grew up with "sizeof *p" thing (very C syntax, isn't
it), and encountered macros like that only in a newsgroup,
then I guess those macros look silly.
Pay attention. I'm a novice. I first
encountered sizeof *p within the last
12 months. Prior to that, I thought
that "sizeof(type)" was the only valid
format. I saw sizeof *p on this newsgroup
and gave it some consideration and realized
that it is "the right thing" (tm). I
saw this macro, gave it consideration,
and rejected it because I believe it's
bogus.
Say, some people's
"no goto, ever" rule is totally stupid for me, but I wouldn't
say those people should or should not use goto.
We're totally in agreement. I think goto is
a powerful statement and I think that the claim
that it should be completely avoided is silly.
They shouldn't
*tell me* that I am wrong if I indeed use goto..
Just to be clear, in case you missed it: I don't
think that you are wrong if you use this macro.
I do think that you are missing out on a
better model.
Your example maybe?
x = malloc(sizeof *p);
is maintainable? I'd think it's a line of code which
strikes you immediately as wrong.
Yes, it does. And if I saw it, I would
immediately check the declaration of x,
realize it was void *, and know that
it is intended to point at an object
of type *p. Not only that it will point
at an object of the same type as *p, but
pretty likely it will either point directly
to an entry in p, or it will be used
to hold copies of items in p. On the
other hand, if I see:
int *p;
int *q;
void *x;
....
x = typeMalloc( int, N );
I don't know if x is related to p or q.