 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Warp wrote:
> Orchid XP v8 <voi### [at] dev null> wrote:
>>>>> Since sizeof() of an array returns the total amount of bytes taken by
>>>>> an array, if you divide it by the amount of bytes of one element, you get
>>>>> the total number of elements.
>>>> This is plain. What surprises me is that sizeof() can give you an
>>>> accurate size in the first place.
>>> Why wouldn't it? The compiler has to know the size of the array if it
>>> wants to allocate it in memory.
>
>> All that stuff about "C does not know the size of an array at run-time,
>> and does not check array bounds".
>
> That talks about dynamically allocated arrays, not statically allocated
> ones. They are different.
He's right, tho. C doesn't know the size of an array at run time. sizeof()
is a compile-time operator.
--
Darren New, San Diego CA, USA (PST)
Forget "focus follows mouse." When do
I get "focus follows gaze"?
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Warp wrote:
> Darren New <dne### [at] san rr com> wrote:
>> Warp wrote:
>>> Also the syntax of indexing an array and indexing memory using a pointer
>>> is identical, adding to the confusion.
>
>> Plus, you can't pass an array to a function, at least in C.
>
> Not directly, but you can do it indirectly if you enclose the array inside
> a struct (in that case the array (inside the struct) is truly passed by
> value rather than by-pointer).
And in the original versions of C, you couldn't pass a struct by value
either. :-)
But yah, that's a good point I hadn't considered.
--
Darren New, San Diego CA, USA (PST)
Forget "focus follows mouse." When do
I get "focus follows gaze"?
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
--
- Warp
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Out of curiosity I changed the location of the light to see that it really
renders it properly:
http://warp.povusers.org/images/smallpt.jpg
--
- Warp
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Darren New
Subject: Re: 99 lines of C++ for an unbiased ray tracer
Date: 14 Jan 2010 23:50:25
Message: <4b4ff411@news.povray.org>
|
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Darren New <dne### [at] san rr com> wrote:
> Well, no, I disagree. How do you find the size of an array at runtime?
It's a constant integral value, hence known at runtime.
> That's exactly why you have to pass it around along with the pointer.
Now you are confusing dynamically allocated arrays with static arrays.
They are not the same thing.
The size of dynamically allocated arrays cannot be resolved either at
runtime nor at compile time (eg. you cannot use the size of a dynamically
allocated array somewhere where a compile-time constant is expected).
> Hmmm... If you put an array in a struct, can you ask
> "sizeof(myrecord.thearray)" and get an appropriate size?
Yes, actually.
> I suppose you
> could, but still I wouldn't count that as such.
"As such"? What? Runtime? sizeof() always works at compile time.
--
- Warp
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: nemesis
Subject: Re: 99 lines of C++ for an unbiased ray tracer
Date: 15 Jan 2010 09:48:31
Message: <4b50803f@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Warp escreveu:
> Out of curiosity I changed the location of the light to see that it really
> renders it properly:
>
> http://warp.povusers.org/images/smallpt.jpg
did you make it coincident with the surface?
--
a game sig: http://tinyurl.com/d3rxz9
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
nemesis <nam### [at] gmail com> wrote:
> Warp escreveu:
> > Out of curiosity I changed the location of the light to see that it really
> > renders it properly:
> >
> > http://warp.povusers.org/images/smallpt.jpg
> did you make it coincident with the surface?
I have hard time deciding whether that was humorous or a serious question.
--
- Warp
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: nemesis
Subject: Re: 99 lines of C++ for an unbiased ray tracer
Date: 15 Jan 2010 11:20:32
Message: <4b5095d0@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Warp escreveu:
> nemesis <nam### [at] gmail com> wrote:
>> Warp escreveu:
>>> Out of curiosity I changed the location of the light to see that it really
>>> renders it properly:
>>>
>>> http://warp.povusers.org/images/smallpt.jpg
>
>> did you make it coincident with the surface?
>
> I have hard time deciding whether that was humorous or a serious question.
serious. Did you put right where the left sphere surface would hit?
--
a game sig: http://tinyurl.com/d3rxz9
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
nemesis <nam### [at] gmail com> wrote:
> Warp escreveu:
> > nemesis <nam### [at] gmail com> wrote:
> >> Warp escreveu:
> >>> Out of curiosity I changed the location of the light to see that it really
> >>> renders it properly:
> >>>
> >>> http://warp.povusers.org/images/smallpt.jpg
> >
> >> did you make it coincident with the surface?
> >
> > I have hard time deciding whether that was humorous or a serious question.
> serious. Did you put right where the left sphere surface would hit?
Unbiased monte-carlo rendering sends rays in a random fashion. It starts
extremely grainy, but the graininess gets reduced over time as the number
of samples gets increased. That image is the result of 30 minutes of
rendering in my computer (a virtually grainless result would have taken
days).
--
- Warp
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |