Flash said:
Yevgen Muntyan wrote, On 09/02/07 12:47:
I note you failed to address the point about your example not being
applicable.
ALLOC_A_THING passes default options to
custom_allocator_with_some_options. And yes, I am talking about specific
cases of course. It's said here "ALLOC_A_THING" is never
needed/good/better. I am saying that
ALLOC_A_THING()
may be much better than
alloc_something (sizeof (ThatType), FOO_BAR | FOO_BAZ);
You also fail to address this point.
I didn't want just to say that yes that IS a workaround. You have
to use nasty sizeof *ptr to make sure size if correct there. I believe
another workaround is better: provide correct type and make the result
have that type instead of void*. And "better" here means "nicer for me,
and no worse in any technical aspect".
Then write a fooalocator function that returns a pointer to a properly
initialised foo. It *still* does not need a cast.
Now your argument is "don't do this and do that instead". You may think
it's good to write thousand
AnyStruct *
any_struct_new (void)
{
return malloc (sizeof (AnyStruct));
}
functions, duplicate them in all source files since they must be static
(or make sure their names don't clash with anything else, and then
make sure the symbols are not exported from the lib), I don't think so.
Now, if there is no allocate_foo(), then if I need raw chunk of memory
for struct Foo, I prefer an expression of type Foo* to an expression
of type void*.
If the function takes bar* and you pass it a foo* then the compiler
*will* warn you, this has nothing to do with casting the value returned
by malloc. The same for return values.
How about assignment? Your workaround is to use "sizeof *ptr" thing,
mine is to use an expression of correct type. As to arguments and
return values I was thinking rather of
Something *func (void)
{
return malloc (sizeof (Something));
}
(the fooallocator function). This is a bit silly example of course,
but though it's already better than invocation of malloc right in code;
and I sometimes have such functions to make them do more later.
Yeah yeah, I *must* make it
Something *func (void)
{
Something *s;
s = malloc (sizeof (Something));
return s;
}
to avoid being beaten by typeless malloc.
No, you refuse to admit to the possibility that what has been suggested
might be better. You seem to ignore at least half the counter points to
your argument. Arguing with someone who does not address the counters to
the points he raises is pointless, so bye.
It's hard to argue here and address same points again and again,
and it's hard to express what I think in English, and it's hard
to filter valid questions out of "wrong." junk. See, you are asking
technical questions, and then you make a conclusion about insistance,
refusal, and other words I hardly understand. And then you're saying
I must answer your questions or otherwise it's pointless to talk
to me, but I am stubborn as a donkey in any case, right from start.
Bye.