Hacker News new | ask | show | jobs
by posterboy 2874 days ago
where's the difference if you put in the numbers by hand? Which numbers do you put in to avoid mentioning the size of the type?
1 comments

You just feed sizeof the instance of the object you're allocating memory for. That entails funky pseudo-dereferences for pointers so the compiler doesn't give you the size of a pointer. It will look up the object's type and requisite size to fill in the argument to malloc(). If the object in question has an unknown type (maybe all you've got is a void *) then you will have to provide the size by other means.