POV-Ray : Newsgroups : povray.off-topic : 99 lines of C++ for an unbiased ray tracer : Re: 99 lines of C++ for an unbiased ray tracer Server Time
5 Sep 2024 01:24:58 EDT (-0400)
  Re: 99 lines of C++ for an unbiased ray tracer  
From: Darren New
Date: 14 Jan 2010 23:50:25
Message: <4b4ff411@news.povray.org>
Warp wrote:
> Darren New <dne### [at] sanrrcom> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.