Quote:
I would prefer to ask for space for objects of the same type as the pointer, and not have to worry about what the type is specifically.
Yeah, what the hell does it matter what you actually need?
Quote:
Once I replace sizeof(type) with sizeof(object of same type as pointer), then I don't "need" the cast that helps hide the above bug.
But once again you're explicitly including the type in the expression. Do you declare a new pointer everytime you need some memory? If not how are you sure you've always got the correct type?
Quote:
How does a variable lose its type?
Where did I say the variable loses its type?
int i = 0;
//some code
i=10;
what is i?
It hasn't lost it's type. But the programmer is using a variable called i without explicitly using the type.
Quote:
Actually, no. I didn't want space for 20 pointers; I wanted space for 20 objects.
This is true.
Quote:
No, t is a pointer of some type. And sizeof(*t) is -- ahem -- the size of the object to which it points, whatever type that may be.
and this. I'm sorry.
Quote:
Actually I didn't care what the underlying type of t was because it no longer mattered. Whatever type it is, I'm asking for space for 20 of them. Because I didn't ask for space for a number of a presumed type -- I instead asked for space for a number of objects of the same type as the pointer -- this problem does not arise.
WTF?? Of course you care what the underlying type is. If you want space for 20 int's, you want space for 20 int's. I can't see how what you've described could be anymore ass-backwards. Let's take some pointer type and hope the data fits.
Quote:
Then you change t to anothertype and you have two more places to edit. I don't.
How? You've got at least one place to edit by changing your type somewhere. I'd only have one if I used a macro.