Re:Remotely Compromising Android and iOS via a bug in Broadc...
by DiThi on Sunday July 30, 2017 @08:17AM
(#14885621)
`sizeof(a)` only gives the size of the array when the size is specified at compile time. Either you accept e.g. `int[16]` as a type, or you pass a pointer (for which `sizeof` just returns `sizeof(intptr_t)`)
[ Parent
| on HN ]
Re:Remotely Compromising Android and iOS via a bug in Broadc...
by nemetroid on Sunday July 30, 2017 @05:26PM
(#14887915)
That's not quite right. Arrays always have a knowable length, and sizeof will give a correct result for variable length arrays as well.
However, arrays that are passed as arguments to functions decay into raw pointers, at which point you lose information about its length.
Re:Remotely Compromising Android and iOS via a bug in Broadc...
by DiThi on Monday July 31, 2017 @07:31AM
(#14890975)
> sizeof will give a correct result for variable length arrays as well.
In C99 with rather spotty support. And never with malloc and similar, which is how the vast majority of arrays are (and can be) created. And you can't return or store those dynamic arrays somewhere else without losing the size info, nor it can be declared static.
In other words, you're right but for very limited situations.