Re: init



osmium wrote:
<bob@xxxxxxxxxxxxxx> wrote:

why won't this work?

float boxcenter[3];

if (nodectr == 0)
boxcenter = {centerpt[0] + halfwidth/2.0, centerpt[1] + halfwidth/2.0,
>>centerpt[2] + halfwidth/2.0};

boxcenter is an array. How does the compiler know which element you are talking about?

He's trying to do the whole array in one setting, see { 0, 1, 2 }


Problem is, that only works when initializing the array;
float boxcenter[3] = { ... }
Other than that you have to do each element separately. At best (AFAIK) that can be automated by a function like

void floatarray ( float* put, float get0, float get1, float get2 ) {
put[0]=get0;
put[1]=get1;
put[2]=get2;
}


Btw, aren't you allocating 4 floats in that array? The case where the last one is not to be used I believe is zero-terminated strings.
(Too long since I've been using arrays, can anyone confirm that?)
.



Relevant Pages

  • Re: weird code.
    ... never seen this kind of declaration ever. ... The variable data is a float pointer? ... array of 16384 float objects. ...
    (comp.lang.c)
  • Re: Help a beginner - function with pointer ...
    ... i thought (float *) T would be appealing to ... The result is the value obtained by converting the ... `T' refers to a one-dimensional array whose elements are also ... using a pointer to the array's first element. ...
    (comp.lang.c)
  • Re: weird code.
    ... The variable data is a float pointer? ... array of 16384 float objects. ... We just write `sizeof *data' and the compiler (knowing what ...
    (comp.lang.c)
  • Re: Vector efficiency
    ... <float>.get(i) to retrieve each record versus aligning the data into an array declared as float, and noticed about 2x computational speed improvement. ... I guess there are a number of step performing a look up with vector has to do as opposed to simple addressing through an array. ... There's also the memory issue (c.f. another ... Expenditure of computer time is not the only ...
    (comp.lang.java.help)
  • Re: new foo[42]
    ... > First question: ... 42 type 'float' objects, and returns the address ... value in the pointer object 'foo'. ... The first form above dynamically allocates an array (which ...
    (comp.lang.cpp)