|
![](/i/fill.gif) |
Warp wrote:
> Darren New <dne### [at] san rr com> wrote:
>> He's right, tho. C doesn't know the size of an array at run time. sizeof()
>> is a compile-time operator.
>
> If it knows it at compile time, it knows it at runtime. It's not like
> it forgets somewhere in between... :P
Well, no, I disagree. How do you find the size of an array at runtime?
That's exactly why you have to pass it around along with the pointer.
OK, I'll grant you that the generated code has that available, in the sense
that the loader avoids overwriting that space with other stuff, but it's not
available to the C-level program in any way at runtime.
You can take sizeof(x) at compile time, and store that somewhere that
runtime can find it, but there's nothing like Ada's myvariable'size
expression that would tell you at runtime what the size is for an arbitrary
array. There's no way to apply sizeof() to a non-array-name and find out the
size of an array (i.e., no way to say "what's the size of the array this
pointer points to").
Hmmm... If you put an array in a struct, can you ask
"sizeof(myrecord.thearray)" and get an appropriate size? I suppose you
could, but still I wouldn't count that as such.
--
Darren New, San Diego CA, USA (PST)
Forget "focus follows mouse." When do
I get "focus follows gaze"?
Post a reply to this message
|
![](/i/fill.gif) |