Hacker News new | ask | show | jobs
by ori_b 6025 days ago
Simple rule: Don't use sizeof on pointers. And don't typedef arrays to make them look like simple types.
1 comments

A better simple rule: always use sizeof on typename. That always works therefore you can use typedef arrays too.
Totally agree. If you start relying on the subtle behaviour of sizeof, it's just asking for a world of trouble. It's so easy to get mixed up with whether it's going to return the length of the array, the size of the elements in the array, the total number of bytes the array is using or the size of the pointer. Come to think of it, I think that's completely scope dependent and depends on whether the array has lots its array-ness. I have no idea. :)