COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### passing static 2D array to function - not fully working like I hoped for...

• Email
• Follow

```Hi all

Noob question:

---------------------------------------------------------------------------=
--
typedef float GLfloat; // float =3D GLfloat

void setBezierPoint(const double &x, const double &y, const double &z,
const int &P, GLfloat bezierCTRpts[][3])
{
bezierCTRpts[P][0] =3D (GLfloat)x;
bezierCTRpts[P][1] =3D (GLfloat)y;
bezierCTRpts[P][2] =3D (GLfloat)z;
}

void FindBezierControlPointsND(const int *N_kontur,
const double *cpp_X, const double *cpp_Y, GLfloat bezierData[]
[3])
{
// calculations...
// set xyz for point P=3D0 using 4th input parameter:
setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, 0, bezierData);

// set xyz for point P=3D3 using 4th input parameter:
setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, 3, bezierData);
}

int main(int argc, char** argv)
{
cout << "hi" << endl;
GLfloat bezierData[4][3] =3D {0};

// something
FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);
}
---------------------------------------------------------------------------=
--

Explanation:

I have a static 2D array: bezierData[4][3], 4 points * xyz-coordinates
and I pass it to FindBezierControlPointsND with this call:

FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);

and the function takes: GLfloat bezierData[][3] as input.
All is ok - the code works, however what I really wanted was to omit
the 4th input parameter (const int &P) so it looks like:

void setBezierPoint(const double &x, const double &y, const double &z,
GLfloat bezierCTRpts[][3]) // 4th input is GONE !
{
bezierCTRpts[0][0] =3D (GLfloat)x;
bezierCTRpts[0][1] =3D (GLfloat)y;
bezierCTRpts[0][2] =3D (GLfloat)z;
}

Then I wanted to set the xyz-values by a function call like:

- for P=3D0:
setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[0][0]);

- for P=3D3:
setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[3][0]);

This however doesn't work! I also tried to add "&" in front of
bezierData[3][0] etc... Error message is something like:

error: cannot convert =91GLfloat* {aka float*}=92 to =91GLfloat* (*)[3] {ak=
a
float* (*)[3]}=92 for argument =914=92 to =91void setBezierPoint(const
double&, const double&, const double&, GLfloat* (*)[3])=92

If you like/ask for it, perhaps I can make a minimal working example.
However, I hope one of you geniuses out there can spot my mistake
right on :-)

THANKS!
```
 0
Reply newsboost (219) 12/29/2011 5:11:08 PM

See related articles to this posting

```someone <newsboost@gmail.com> writes:
<snip>
> -----------------------------------------------------------------------------
> typedef float GLfloat; // float = GLfloat
>
> void setBezierPoint(const double &x, const double &y, const double &z,
>                     const int &P, GLfloat bezierCTRpts[][3])

This is not C!  Did you intend to remove the references?  If you are
really writing C++ there may be much better ways to it.

> {
>   bezierCTRpts[P][0] = (GLfloat)x;
>   bezierCTRpts[P][1] = (GLfloat)y;
>   bezierCTRpts[P][2] = (GLfloat)z;
> }
>
>
> void FindBezierControlPointsND(const int *N_kontur,
>       const double *cpp_X, const double *cpp_Y, GLfloat bezierData[]
> [3])
> {
>   // calculations...
>   // set xyz for point P=0 using 4th input parameter:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, 0, bezierData);
>
>   // set xyz for point P=3 using 4th input parameter:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, 3, bezierData);
> }
>
>
> int main(int argc, char** argv)
> {
>   cout << "hi" << endl;
>   GLfloat bezierData[4][3] = {0};
>
>   // something
>   FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);
> }
> -----------------------------------------------------------------------------
>
> Explanation:
>
> I have a static 2D array: bezierData[4][3], 4 points * xyz-coordinates
> and I pass it to FindBezierControlPointsND with this call:
>
>   FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);
>
> and the function takes: GLfloat bezierData[][3] as input.
> All is ok - the code works, however what I really wanted was to omit
> the 4th input parameter (const int &P) so it looks like:
>
> void setBezierPoint(const double &x, const double &y, const double &z,
>                     GLfloat bezierCTRpts[][3]) // 4th input is GONE !

You need simply to pass a pointer to once bezier tripple, rather than to
(the start of) an array of them.  Then, in the function, you drop the
first index.

void setBezierPoint(const double &x, const double &y, const double &z,
GLfloat bezierCTRpt[])
{
bezierCTRpt[0] = x;
bezierCTRpt[1] = y;
bezierCTRpt[2] = z;
}

(I make the name singular since there is now one point being passed).
Note that the casts are no needed -- they just clutter up the code in my
opinion.

> Then I wanted to set the xyz-values by a function call like:
>
> - for P=0:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[0][0]);
>
> - for P=3:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[3][0]);

Here you drop the second index or add and & operator:

setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[3]);
setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, &bezierData[3][0]);

> This however doesn't work! I also tried to add "&" in front of
> bezierData[3][0] etc... Error message is something like:

You were so close.  Have a read of the C FAQ -- arrays are a little
fiddly: http://c-faq.com/

Post a follow up if you don't see why this works (or if I've got
the wrong end of the stick).

<snip>
--
Ben.
```
 0
Reply ben.usenet (6790) 12/29/2011 5:27:53 PM

```someone <newsboost@gmail.com> wrote:

Please note that your code is C++ while this is a C newsgroup.
It would be more prudent if you would post to comp.land.c++,
where the C++ experts are to be found. But since there's no
big difference here between C and C++ I'll try to come up
with a proposal:

> -----------------------------------------------------------------------------
> typedef float GLfloat; // float = GLfloat

> void setBezierPoint(const double &x, const double &y, const double &z,
>                     const int &P, GLfloat bezierCTRpts[][3])
> {
>   bezierCTRpts[P][0] = (GLfloat)x;
>   bezierCTRpts[P][1] = (GLfloat)y;
>   bezierCTRpts[P][2] = (GLfloat)z;
> }

> void FindBezierControlPointsND(const int *N_kontur,
>       const double *cpp_X, const double *cpp_Y, GLfloat bezierData[][3])
> {
>   // calculations...
>   // set xyz for point P=0 using 4th input parameter:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, 0, bezierData);

>   // set xyz for point P=3 using 4th input parameter:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, 3, bezierData);
> }

> int main(int argc, char** argv)
> {
>   cout << "hi" << endl;
>   GLfloat bezierData[4][3] = {0};

>   // something
>   FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);
> }
> -----------------------------------------------------------------------------

> Explanation:

> I have a static 2D array: bezierData[4][3], 4 points * xyz-coordinates
> and I pass it to FindBezierControlPointsND with this call:

>   FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);

> and the function takes: GLfloat bezierData[][3] as input.
> All is ok - the code works, however what I really wanted was to omit
> the 4th input parameter (const int &P) so it looks like:

> void setBezierPoint(const double &x, const double &y, const double &z,
>                     GLfloat bezierCTRpts[][3]) // 4th input is GONE !
> {
>   bezierCTRpts[0][0] = (GLfloat)x;
>   bezierCTRpts[0][1] = (GLfloat)y;
>   bezierCTRpts[0][2] = (GLfloat)z;
> }

Why then not make it

void setBezierPoint(const double &x, const double &y, const double &z,
GLfloat bezierCTRpts[3])
{
bezierCTRpts[0] = (GLfloat)x;
bezierCTRpts[1] = (GLfloat)y;
bezierCTRpts[2] = (GLfloat)z;
}

Note that the casts to 'GLfloat' are rather likely unnecessary
- why did you put them in? I would recomend to use casts only
when they are really needed (and since you're doing C++ you
also should be using C++-style casts if you have a good reason
to use them.

> Then I wanted to set the xyz-values by a function call like:

> - for P=0:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[0][0]);

> - for P=3:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[3][0]);

With the modified signature of setBezierPoint() you know can
call it like

setBezierPoint( cpp_X[0], cpp_Y[0], 0.0, bezierData[0]);

setBezierPoint( cpp_X[0], cpp_Y[0], 0.0, bezierData[3]);

since setBezierPoint() now expects a simple array with 3 elements
and that's what you pass it that way.

Regards, Jens
--
\   Jens Thoms Toerring  ___      jt@toerring.de
\__________________________      http://toerring.de
```
 0
Reply jt68 (1148) 12/29/2011 5:34:23 PM

```On Thu, 29 Dec 2011 09:11:08 -0800 (PST), someone
<newsboost@gmail.com> wrote:

>Hi all
>
>Noob question:
>
>-----------------------------------------------------------------------------
>typedef float GLfloat; // float = GLfloat
>
>void setBezierPoint(const double &x, const double &y, const double &z,
>                    const int &P, GLfloat bezierCTRpts[][3])

snip

You are looking fro comp.lang.c++.  Down the hall, turn left at the
vending machine, third door on the right.

--
Remove del for email
```
 0
Reply schwarzb3978 (1428) 12/29/2011 5:49:34 PM

```On Dec 29, 6:27=A0pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> someone <newsbo...@gmail.com> writes:
>
> <snip>
>
> > -----------------------------------------------------------------------=
------
> > typedef float GLfloat; // float =3D GLfloat
>
> > void setBezierPoint(const double &x, const double &y, const double &z,
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const int &P, GLfloat bezierCTR=
pts[][3])
>
> This is not C! =A0Did you intend to remove the references? =A0If you are
> really writing C++ there may be much better ways to it.

I forgot that &(var) is C++, however I think that is the only thing I
forgot... I even added a typedef in the beginning to avoid someone
telling me that GLfloat "is not part of the C-standard, hence not a
question for this group"...

I am/was looking for the "C-answer", not a "C++-answer", so that's why
I thought it is better to post to here...

..........................

> > Explanation:
>
> > I have a static 2D array: bezierData[4][3], 4 points * xyz-coordinates
> > and I pass it to FindBezierControlPointsND with this call:
>
> > =A0 FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);
>
> > and the function takes: GLfloat bezierData[][3] as input.
> > All is ok - the code works, however what I really wanted was to omit
> > the 4th input parameter (const int &P) so it looks like:
>
> > void setBezierPoint(const double &x, const double &y, const double &z,
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 GLfloat bezierCTRpts[][3]) // 4=
th input is GONE !
>
> You need simply to pass a pointer to once bezier tripple, rather than to
> (the start of) an array of them. =A0Then, in the function, you drop the
> first index.

Aaah, thank you very much!

> =A0 void setBezierPoint(const double &x, const double &y, const double &z=
,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 GLfloat bezierCTRpt[])
> =A0 {
> =A0 =A0 bezierCTRpt[0] =3D x;
> =A0 =A0 bezierCTRpt[1] =3D y;
> =A0 =A0 bezierCTRpt[2] =3D z;
> =A0 }
>
> (I make the name singular since there is now one point being passed).
> Note that the casts are no needed -- they just clutter up the code in my
> opinion.

Thank you!

> > Then I wanted to set the xyz-values by a function call like:
>
> > - for P=3D0:
> > =A0 setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[0][0]);
>
> > - for P=3D3:
> > =A0 setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[3][0]);
>
> Here you drop the second index or add and & operator:
>
> =A0 =A0setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[3]);
> =A0 =A0setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, &bezierData[3][0]);

I see...

> > This however doesn't work! I also tried to add "&" in front of
> > bezierData[3][0] etc... Error message is something like:
>
> You were so close. =A0Have a read of the C FAQ -- arrays are a little
> fiddly:http://c-faq.com/

I tried to google quite some answers but couldn't find exactly this
little problem anywhere... Maybe q.6.18 from the C-faq should've
helped me.

In any case, it's great that there are people to help each other
around in here - thank you very much, Ben!

> Post a follow up if you don't see why this works (or if I've got
> the wrong end of the stick).

I get the idea now, thanks :-)
```
 0
Reply newsboost (219) 12/29/2011 6:55:20 PM

```On Dec 29, 6:34=A0pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> someone <newsbo...@gmail.com> wrote:
>
> Please note that your code is C++ while this is a C newsgroup.

Maybe 1% C++ and 99% C, ok.

> It would be more prudent if you would post to comp.land.c++,
> where the C++ experts are to be found. But since there's no

No, I don't think so.

> big difference here between C and C++ I'll try to come up
> with a proposal:

.................

> > Explanation:
> > I have a static 2D array: bezierData[4][3], 4 points * xyz-coordinates
> > and I pass it to FindBezierControlPointsND with this call:
> > =A0 FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);
> > and the function takes: GLfloat bezierData[][3] as input.
> > All is ok - the code works, however what I really wanted was to omit
> > the 4th input parameter (const int &P) so it looks like:
> > void setBezierPoint(const double &x, const double &y, const double &z,
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 GLfloat bezierCTRpts[][3]) // 4=
th input is GONE !
> > {
> > =A0 bezierCTRpts[0][0] =3D (GLfloat)x;
> > =A0 bezierCTRpts[0][1] =3D (GLfloat)y;
> > =A0 bezierCTRpts[0][2] =3D (GLfloat)z;
> > }
>
> Why then not make it
>
> void setBezierPoint(const double &x, const double &y, const double &z,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0GLfloat bezierCTRpts[3])
> {
> =A0 bezierCTRpts[0] =3D (GLfloat)x;
> =A0 bezierCTRpts[1] =3D (GLfloat)y;
> =A0 bezierCTRpts[2] =3D (GLfloat)z;
>
> }

Thank you very much.

> Note that the casts to 'GLfloat' are rather likely unnecessary
> - why did you put them in? I would recomend to use casts only

Actually I cast double -> float, so I make the intermediate
calculations using double precision, but when it comes to actually
storing the data, I save it as a float (less precision). Normally I
would be doing everything with double precision...

Of some reason, floats seem to be widely used with opengl... Don' ask
me why - I don't know. That's why I cast. I could also cast before
calling the function, of course...

> when they are really needed (and since you're doing C++ you
> also should be using C++-style casts if you have a good reason
> to use them.

I don't see why, if it works and apparently it does work out fine with
C?

> > Then I wanted to set the xyz-values by a function call like:
> > - for P=3D0:
> > =A0 setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[0][0]);
> > - for P=3D3:
> > =A0 setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[3][0]);
>
> With the modified signature of setBezierPoint() you know can
> call it like
>
> =A0 =A0 setBezierPoint( cpp_X[0], cpp_Y[0], 0.0, bezierData[0]);
>
> =A0 =A0 setBezierPoint( cpp_X[0], cpp_Y[0], 0.0, bezierData[3]);
>
> since setBezierPoint() now expects a simple array with 3 elements
> and that's what you pass it that way.

That's great Jens. Thank you very much. Appreciate your help and
time...
```
 0
Reply newsboost (219) 12/29/2011 7:03:46 PM

```On Dec 29, 6:49=A0pm, Barry Schwarz <schwa...@dqel.com> wrote:
> On Thu, 29 Dec 2011 09:11:08 -0800 (PST), someone
>
> <newsbo...@gmail.com> wrote:
> >Hi all
>
> >Noob question:
>
> >------------------------------------------------------------------------=
-----
> >typedef float GLfloat; // float =3D GLfloat
>
> >void setBezierPoint(const double &x, const double &y, const double &z,
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const int &P, GLfloat bezierCTRp=
ts[][3])
>
> snip
>
> You are looking fro comp.lang.c++.

No I'm not.
```
 0
Reply newsboost (219) 12/29/2011 7:13:46 PM

```On 2011-12-29, someone <newsboost@gmail.com> wrote:
>> You are looking fro comp.lang.c++.

> No I'm not.

I'm curious as to why you say this.  Your code is obviously C++.  Nothing
similar to it has ever been part of C.

Granted that a similar question could apply to C, the mere fact that you're
using references means that the rules for what you're doing are certainly
going to be different.

So the question is:  Why *aren't* you looking for a C++ group?  Do you think
that they would be unable to answer your question?  If so, why?

-s
--
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
```
 0
Reply usenet-nospam (2309) 12/29/2011 7:22:58 PM

```someone <newsboost@gmail.com> wrote:
> On Dec 29, 6:34 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> > someone <newsbo...@gmail.com> wrote:
> >
> > Please note that your code is C++ while this is a C newsgroup.

> Maybe 1% C++ and 99% C, ok.

Well, there are sume subtle differences between C and C++
and when you write C++ (i.e. use a C++ compiler, your program
won't compile with a C compiler) then it's typically better
to ask in the correct group - it may safe you a lot of time
and grieve. And sometimes there are also more elegant so-
lutions to a problem in C++.

> > Note that the casts to 'GLfloat' are rather likely unnecessary
> > - why did you put them in? I would recomend to use casts only

> Actually I cast double -> float, so I make the intermediate
> calculations using double precision, but when it comes to actually
> storing the data, I save it as a float (less precision). Normally I
> would be doing everything with double precision...

All calculations are done in double anyway (even if you
use floats - and on quite a number of architectures even
with an even wider representation than double, i.e. on
x86 you often have 64 bit doubles but computation are all
done with 80 bit) and if you assign to a float the value
will be converted to a float without any cast.

> Of some reason, floats seem to be widely used with opengl...

Probably because the results don't need a high precision (does
it matter if a pixel is shown at position 231.122387267423 or
231.122387267424?) and floats often take only half as much
space as doubles to store.
Regards, Jens
--
\   Jens Thoms Toerring  ___      jt@toerring.de
\__________________________      http://toerring.de
```
 0
Reply jt68 (1148) 12/29/2011 7:38:38 PM

```someone <newsboost@gmail.com> writes:
> On Dec 29, 6:34 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
>> someone <newsbo...@gmail.com> wrote:
>>
>> Please note that your code is C++ while this is a C newsgroup.
>
> Maybe 1% C++ and 99% C, ok.

There's a term for code that's 1% CZ++ and 99% C.  We call it "C++".

There are at least 2 C++-specific things in your code: the parameters of
setBezierPoint are C++ references, and you use "cout << ..." in main().

And even if those are corrected, you have no declaration for N_kontur,
Xval, or Yval.

It's not a *huge* deal, but for future reference it's best to post
straight C code here.  Compile it with a C compiler and copy-and-paste
the exact code that you compiled.  Otherwise, it can be difficult to
tell whether your problems are C++-specific and/or whether they're
related to errors you made when you re-typed the code.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
```
 0
Reply kst-u (21963) 12/29/2011 7:58:34 PM

```On 12/29/2011 02:03 PM, someone wrote:
> On Dec 29, 6:34 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
>> someone <newsbo...@gmail.com> wrote:
....
>>> Explanation:
>>> I have a static 2D array: bezierData[4][3], 4 points * xyz-coordinates
>>> and I pass it to FindBezierControlPointsND with this call:
>>>   FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);
>>> and the function takes: GLfloat bezierData[][3] as input.
>>> All is ok - the code works, however what I really wanted was to omit
>>> the 4th input parameter (const int &P) so it looks like:
>>> void setBezierPoint(const double &x, const double &y, const double &z,
>>>                     GLfloat bezierCTRpts[][3]) // 4th input is GONE !
>>> {
>>>   bezierCTRpts[0][0] = (GLfloat)x;
>>>   bezierCTRpts[0][1] = (GLfloat)y;
>>>   bezierCTRpts[0][2] = (GLfloat)z;
>>> }

There's really no reason for using C++ references here. You're not
changing the thing they refer to. C++ references are just syntactic
sugar for something that could also be done in ordinary C using pointers
(don't get me wrong - I like some kinds of syntactic sugar, and C++
references can be useful). By using a reference, you avoid a copy, but
impose the cost of dereferencing the pointer - it's pretty much a wash,
unless the parameter has a big complicated type - which isn't the case
for double.

>> Why then not make it
>>
>> void setBezierPoint(const double &x, const double &y, const double &z,
>>                    GLfloat bezierCTRpts[3])
>> {
>>   bezierCTRpts[0] = (GLfloat)x;
>>   bezierCTRpts[1] = (GLfloat)y;
>>   bezierCTRpts[2] = (GLfloat)z;
>>
>> }
>
> Thank you very much.
>
>> Note that the casts to 'GLfloat' are rather likely unnecessary
>> - why did you put them in? I would recomend to use casts only
>
> Actually I cast double -> float, so I make the intermediate
> calculations using double precision, but when it comes to actually
> storing the data, I save it as a float (less precision). Normally I
> would be doing everything with double precision...
>
> Of some reason, floats seem to be widely used with opengl... Don' ask
> me why - I don't know. That's why I cast.

But it doesn't make any difference; the conversion specified by the cast
will occur automatically even if you don't write the cast.

> ... I could also cast before
> calling the function, of course...

With the current declaration, that would be a waste of time; the values
would be converted back to double before executing the function call. If
you changed the function's declaration to have it take float parameters,
the conversion would occur automatically as a result of calling the
function, whether or not you used a cast. It wouldn't make much
difference compared to the current code.

>> when they are really needed (and since you're doing C++ you
>> also should be using C++-style casts if you have a good reason
>> to use them.
>
> I don't see why, if it works and apparently it does work out fine with
> C?

C++'s specialized casts aren't needed here, for precisely the same
reason that the C casts aren't needed. However, where a cast is needed,
C++'s specialized casts are better because a diagnostic message is
mandatory if the combination of the type of the argument and the result
type violates the requirements of the specialized cast. It's just a
matter of choosing the appropriate specialized cast for the conversion
you want performed - in this case, static_cast<>. The diagnostic makes
it easier to detect problems due to giving the wrong expression or the
wrong result type, or the wrong specialized cast.

If you're certain you'll never make any such mistake, then it doesn't
matter. I don't think it's possible to be sanely certain of such things.
However, it is possible to sanely believe it's too much additional work
to justify bothering with.
```
 0
Reply jameskuyper (5639) 12/29/2011 8:35:51 PM

```someone <newsboost@gmail.com> writes:

> On Dec 29, 6:34 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
>> someone <newsbo...@gmail.com> wrote:
<snip>
>> > void setBezierPoint(const double &x, const double &y, const double &z,
>> >                     GLfloat bezierCTRpts[][3]) // 4th input is GONE !
>> > {
>> >   bezierCTRpts[0][0] = (GLfloat)x;
>> >   bezierCTRpts[0][1] = (GLfloat)y;
>> >   bezierCTRpts[0][2] = (GLfloat)z;
>> > }
<snip>
>> Note that the casts to 'GLfloat' are rather likely unnecessary
>> - why did you put them in? I would recomend to use casts only
>
> Actually I cast double -> float, so I make the intermediate
> calculations using double precision, but when it comes to actually
> storing the data, I save it as a float (less precision).

You may be confusing "cast" with "convert".  Jens (and I) were saying
that the *casts* are unnecessary, not the conversion.  C's assignment
includes and implicit conversion from the type of the right hand side to
that of the left hand side.  The cast is superfluous.

<snip>
--
Ben.
```
 0
Reply ben.usenet (6790) 12/29/2011 8:37:26 PM

```James Kuyper <jameskuyper@verizon.net> writes:
> On 12/29/2011 02:03 PM, someone wrote:
>> On Dec 29, 6:34 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
>>> someone <newsbo...@gmail.com> wrote:
[...]
>>>> void setBezierPoint(const double &x, const double &y, const double &z,
>>>>                     GLfloat bezierCTRpts[][3]) // 4th input is GONE !
>>>> {
[...]
>>>> }
>
> There's really no reason for using C++ references here. You're not
> changing the thing they refer to. C++ references are just syntactic
> sugar for something that could also be done in ordinary C using pointers
> (don't get me wrong - I like some kinds of syntactic sugar, and C++
> references can be useful). By using a reference, you avoid a copy, but
> impose the cost of dereferencing the pointer - it's pretty much a wash,
> unless the parameter has a big complicated type - which isn't the case
> for double.

And in this case, it doesn't make much sense to use a reference even in
C++.  You're passing the argument by reference, byt the "const" means
the function can't use the reference to modify the argument anyway.

In either C or C++, you might as well define the function as:

void setBezierPoint(double x, double y, double z,
GLfloat bezierCTRpts[][3])
{
[...]
}

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
```
 0
Reply kst-u (21963) 12/29/2011 9:25:08 PM

```On Dec 29, 8:22=A0pm, Seebs <usenet-nos...@seebs.net> wrote:
> On 2011-12-29, someone <newsbo...@gmail.com> wrote:
>
> >> You are looking fro comp.lang.c++.
> > No I'm not.
>
> I'm curious as to why you say this. =A0Your code is obviously C++. =A0Not=
hing
> similar to it has ever been part of C.

I'm saying it because it's true.

> Granted that a similar question could apply to C, the mere fact that you'=
re
> using references means that the rules for what you're doing are certainly
> going to be different.
>
> So the question is: =A0Why *aren't* you looking for a C++ group? =A0Do yo=
u think
> that they would be unable to answer your question? =A0If so, why?

I already explained this, pretty clear I think.
What interest do you have in whether or not any other C++ group would
(or would not) be "unable to answer the question"? Don't worry about
that. I think I'll have to move on with my own project now, sorry I
don't have so much time to continue...

To those who want to continue in this thread: Please go on with your
"C vs. C++" discussions without me and have a nice evening. I don't
think I asked for this, but feel free to continue and e.g. keep
repeating the same things somebody before you already wrote a lot of
times (like: "this is not C, why don't you understand it etc..." and

Thanks a lot to those who understood the C in the question and spend
time answering the C-question. Feel free to continue without me, Peter
Seebach and others (and feel free to repeat yourselves again), thanks
then people will call me a troll or similar and I can find better
things to do in my spare time.

```
 0
Reply newsboost (219) 12/29/2011 9:29:01 PM

```On 2011-12-29, someone <newsboost@gmail.com> wrote:
> I'm saying it because it's true.

Yes, I was asking *why* it's true.  Why are you not looking for a C++ group
for a question which is clearly about C++?

The thing is... The languages are similar, but if you repeatedly ask questions
in a C group because you think they probably apply to C, and you are actually
writing C++, you're gonna get burned on the differences, which people may not
think to bring up.

But whatever.  You seem uninterested in the possibility that there are
differences, you're dismissive and rude, and you've said you aren't interested
in what people have to say if they aren't blithely answering your questions
without any hint of reference to the possibility of differences between C
and C++ which would affect how your code will work.  Good luck with that.

-s
--
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
```
 0
Reply usenet-nospam (2309) 12/29/2011 9:42:54 PM

```someone <newsboost@gmail.com> writes:
> On Dec 29, 8:22 pm, Seebs <usenet-nos...@seebs.net> wrote:
[...]
>> So the question is:  Why *aren't* you looking for a C++ group?  Do you think
>> that they would be unable to answer your question?  If so, why?
>
> I already explained this, pretty clear I think.
[...]
> Thanks a lot to those who understood the C in the question and spend
[...]

What we're trying to explain to you is that C and C++, though
they're closely related, are different languages, and even the
C-like subset of C++ has some quite subtle differences from C.

programs that are mostly written in the C-like subset of that
language.

But if you post something here that's mostly C, but using
C++-specific features, then there's always the very real possibility
that some C vs. C++ incompatibility could be (part of) the cause
of the problem you're asking about.  Many of us here are not C++
experts, and we have no idea whether *you're* familiar enough with
the issues that we can safely ignore them and concentrate on the

If you can take the time to write your code so it's in pure C,
it will make it easier for us to help you -- which, after all,
is what we're trying to do here.

Or if you want to ask about code that can only be compiled with a
C++ compiler (and it's perfectly ok to do that), comp.lang.c++ is a

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
```
 0
Reply kst-u (21963) 12/29/2011 10:46:46 PM

```"Jens Thoms Toerring" <jt@toerring.de> wrote in message
news:9m3ttuFb3eU1@mid.uni-berlin.de...
> someone <newsboost@gmail.com> wrote:

>> Of some reason, floats seem to be widely used with opengl...
>
> Probably because the results don't need a high precision (does
> it matter if a pixel is shown at position 231.122387267423 or
> 231.122387267424?)

When it finally gets to the screen, it doesn't matter. But it might well do
long before that.

Single precision only gives an accuracy of about 1 in 8 million; if the
model you're trying to display uses vertices relative to some distant point
(for example, one particular location in a country), then there could be
obvious errors in the endpoints of the lines you're trying to draw.

Single precision can still be used, if that is all that is available, but
might require some extra ingenuity to use with some kinds of model.

--
Bartc

```
 0
Reply bc (2337) 12/29/2011 11:19:25 PM

```On Dec 29, 10:42=A0pm, Seebs <usenet-nos...@seebs.net> wrote:
> On 2011-12-29, someone <newsbo...@gmail.com> wrote:
>
> > I'm saying it because it's true.
>
> Yes, I was asking *why* it's true. =A0Why are you not looking for a C++ g=
roup
> for a question which is clearly about C++?

Because the question is clearly about C! The question was a C-
question. Understand it or not - hence the group. What part of it is
too hard to understand? I'm afraid I'm making a big mistake just by
answering you now, however I feel I must correct you on the issue
stop wasting more time by repeating that the question was not a C-
question, when I think it was/is... This is the last answer you (and
others who keep repeating the same) will get from me - I promise!

> The thing is... The languages are similar, but if you repeatedly ask ques=
tions

Eerhm, "repeatedly"... Stop wasting my time with this shit, thank you.
How many "repeatedly times" have you counted?

> in a C group because you think they probably apply to C, and you are actu=
ally
> writing C++, you're gonna get burned on the differences, which people may=
not
> think to bring up.

Eerhm, I think I've read the same thing over and over again in this

> But whatever. =A0You seem uninterested in the possibility that there are
> differences, you're dismissive and rude, and you've said you aren't inter=
ested
> in what people have to say if they aren't blithely answering your questio=
ns
> without any hint of reference to the possibility of differences between C
> and C++ which would affect how your code will work. =A0Good luck with tha=
t.

That is the stupidiest thing I've read in the whole thread, causing
this to be my final answer.
1) No, I'm not "uninterested in the possibility that there are
differences". I've never written that anywhere. I read the ontopic
2) So just call me "dismissive and rude" because I don't want to hear/
read all your C++ ideas in a non-C++ newsgroup (I think I should take
that as a complement, because C++ is offtopic here and you keep
insisting on being offtopic, as far as I can judge).
3) No, I never said "you aren't interested in what people have to say
reference to the possibility of differences between C and C++ which
would affect how your code will work" - the fact that you're
postulating that, makes me completely sure that my time is up now and
I've already spend too much time on you by now.
4) I believe I honestly already expressed my gratitude to everyone in
this thread who has helped me and spend time on trying to help me. and
that is practically everyone. Besides, I've read and understood what
everyone wrote and I read it with great interest (except for the
postings that looks just like your post, someone who don't understand
to ignore cout and pass-by-reference no matter if they've been told
one million times or not). That's all I think/feel I can do: To
express my gratitude and we cannot expect anything else here on
usenet, I believe.
5) What I don't like (and reason for me to correct on you), is people
trying to convince somebody (or themself/themselves) that I'm
"dismissive and rude" etc, just because I asked a C-question here
(with 2 mistakes I think, I never said the code was 100% correct, I
wrote: "If you like/ask for it, perhaps I can make a minimal working
example", meaning that the code was only pseudo-code). It seems like
you have an *extremely* hard time understanding, that I was interested
in the C-solution, relevant to C-coding and not the C++-solution,
which is offtopic here. Sorry to say that I cannot (and think it's a
waste of time) to answer more questions in this thread. Those who
received my gratitude should know that I think it's great that they
understood the C-question and I want to thank for that, for that for
the last time now.

[over and out - au revoir]
```
 0
Reply newsboost (219) 12/29/2011 11:28:53 PM

```On 12/29/2011 02:22 PM, Seebs wrote:
> On 2011-12-29, someone <newsboost@gmail.com> wrote:
>>> You are looking fro comp.lang.c++.
>
>> No I'm not.
>
> I'm curious as to why you say this.  Your code is obviously C++.  Nothing
> similar to it has ever been part of C.

Date: Thu, 29 Dec 2011 10:55:20 -0800 (PST)
said:
> I forgot that &(var) is C++, however I think that is the only thing I
> forgot... I even added a typedef in the beginning to avoid someone
> telling me that GLfloat "is not part of the C-standard, hence not a
> question for this group"...
>
> I am/was looking for the "C-answer", not a "C++-answer", so that's why
> I thought it is better to post to here...

It's not entirely clear from the above what's going on, but my
interpretation is that he had C++ code that he wanted to move to C, and
also had some questions about a desired modification of the code. He
tried to translate it to C code, but forgot a couple of things that
should have been changed. The remaining C++ features of the code are
just a mistake, they do not indicate a desire to use C++ to compile this
code. The modification he wants to perform presents pretty much the same
issues in C++ as it does in C; it's merely a coincidence that he's
languages.

If I'm right, and he is looking for a solution that can be compiled by a
conforming C compiler, why is this NOT the right place for him to ask
such questions? It's not clear why he decided to switch from C++ to C,
but you're surely not hostile to the idea that he might have had a good
reason for doing so, are you?
```
 0
Reply jameskuyper (5639) 12/29/2011 11:29:38 PM

```On 2011-12-29, James Kuyper <jameskuyper@verizon.net> wrote:
> The modification he wants to perform presents pretty much the same
> issues in C++ as it does in C; it's merely a coincidence that he's
> languages.

But it's also a coincidence that it offers the same issues in both languages;
there are lots of changes you might make which wouldn't.

And that's the thing; a lot of the posters here wouldn't know whether the
issues would be the same in C++ or not, and can't test the code as is on a
C compiler...

> If I'm right, and he is looking for a solution that can be compiled by a
> conforming C compiler, why is this NOT the right place for him to ask
> such questions?

Oh, that might be.  But...

If he's offering something that cannot possibly ever have even been waved in
the direction of a C compiler, the first interpretation that leaps to mind
is not "I am later going to have rewritten large hunks of this into C, at
which point I want to know how I'd do this."

Basically...  If the question is about the code as is, it's going to get just
as good answers, or better, in a C++ forum.  If it's about a hypothetical
translation of the code to C, it seems premature.  Anything that is using
references strikes me as pretty likely to be changed significantly by a
conversion to C.

-s
--
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
```
 0
Reply usenet-nospam (2309) 12/30/2011 12:03:31 AM

```Jens Thoms Toerring=E6=96=BC 2011=E5=B9=B412=E6=9C=8830=E6=97=A5=E6=98=9F=
=E6=9C=9F=E4=BA=94UTC+8=E4=B8=8A=E5=8D=883=E6=99=8238=E5=88=8638=E7=A7=92=
=E5=AF=AB=E9=81=93=EF=BC=9A
> someone <news...@gmail.com> wrote:
> > On Dec 29, 6:34=C2=A0pm, j....@toerring.de (Jens Thoms Toerring) wrote:
> > > someone <news...@gmail.com> wrote:
> > >
> > > Please note that your code is C++ while this is a C newsgroup.
>=20
> > Maybe 1% C++ and 99% C, ok.
>=20
> Well, there are sume subtle differences between C and C++
> and when you write C++ (i.e. use a C++ compiler, your program
> won't compile with a C compiler) then it's typically better
> to ask in the correct group - it may safe you a lot of time
> and grieve. And sometimes there are also more elegant so-
> lutions to a problem in C++.
>=20
> > > Note that the casts to 'GLfloat' are rather likely unnecessary
> > > - why did you put them in? I would recomend to use casts only
>=20
> > Actually I cast double -> float, so I make the intermediate
> > calculations using double precision, but when it comes to actually
> > storing the data, I save it as a float (less precision). Normally I
> > would be doing everything with double precision...
>=20
> All calculations are done in double anyway (even if you
> use floats - and on quite a number of architectures even
> with an even wider representation than double, i.e. on
> x86 you often have 64 bit doubles but computation are all
> done with 80 bit) and if you assign to a float the value
> will be converted to a float without any cast.
>=20

A float can fit in 32 bits. The lifting of two floats into  doubles of 64 o=
r=20
80 bits either does not increase the  precisions of the two sources at all=
=20
in any math operations but can save the result better than a float.

=20

> > Of some reason, floats seem to be widely used with opengl...
>=20
> Probably because the results don't need a high precision (does
> it matter if a pixel is shown at position 231.122387267423 or
> 231.122387267424?) and floats often take only half as much
> space as doubles to store.
>                              Regards, Jens
> --=20
>   \   Jens Thoms Toerring  ___      j...@toerring.de
>    \__________________________      http://toerring.de

```
 0
Reply dihedral88888 (789) 12/30/2011 1:26:42 AM

```On 12/29/2011 07:03 PM, Seebs wrote:
> On 2011-12-29, James Kuyper <jameskuyper@verizon.net> wrote:
>> The modification he wants to perform presents pretty much the same
>> issues in C++ as it does in C; it's merely a coincidence that he's
>> languages.
>
> But it's also a coincidence that it offers the same issues in both languages;
> there are lots of changes you might make which wouldn't.
>
> And that's the thing; a lot of the posters here wouldn't know whether the
> issues would be the same in C++ or not, and can't test the code as is on a
> C compiler...
>
>> If I'm right, and he is looking for a solution that can be compiled by a
>> conforming C compiler, why is this NOT the right place for him to ask
>> such questions?
>
> Oh, that might be.  But...
>
> If he's offering something that cannot possibly ever have even been waved in
> the direction of a C compiler, the first interpretation that leaps to mind
> is not "I am later going to have rewritten large hunks of this into C, at
> which point I want to know how I'd do this."
>
> Basically...  If the question is about the code as is, it's going to get just
> as good answers, or better, in a C++ forum.  If it's about a hypothetical
> translation of the code to C, it seems premature.  Anything that is using
> references strikes me as pretty likely to be changed significantly by a
> conversion to C.

Not really - if I were handling it, the first step of the conversion
would be to convert the references to pointers, with corresponding
syntax changes in several locations. My second step would have been to
notice that there was no good reason to use pointers; but under the
circumstances, it seems unlikely that the OP would have noticed that
issue. The only other change that seems required is to replace

cout << "hi" << endl;

with
printf("hi\n");

Were there any other changes needed?
--
James Kuyper
```
 0
Reply jameskuyper (5639) 12/30/2011 2:30:14 AM

```On Thu, 29 Dec 2011 11:03:46 -0800, someone wrote:

> Of some reason, floats seem to be widely used with opengl... Don' ask
> me why - I don't know.

OpenGL itself either provides both float and double versions, or just a
double version.

Code which uses OpenGL tends to use double because the extra precision is
usually either entirely pointless (if the hardware only uses single
precision) or mostly pointless (any difference will be imperceptible), and
tends to harm performance (twice the memory consumption, either twice or
four times as many GPU cycles).

```
 0
Reply nobody (5153) 12/31/2011 9:23:54 AM

```"BartC" <bc@freeuk.com> wrote in message news:jdisku\$hbb\$1@dont-email.me...
> "Jens Thoms Toerring" <jt@toerring.de> wrote in message
> news:9m3ttuFb3eU1@mid.uni-berlin.de...
>> someone <newsboost@gmail.com> wrote:
>
>
>>> Of some reason, floats seem to be widely used with opengl...
>>
>> Probably because the results don't need a high precision (does
>> it matter if a pixel is shown at position 231.122387267423 or
>> 231.122387267424?)

> Single precision can still be used, if that is all that is available, but
> might require some extra ingenuity to use with some kinds of model.

options on it's functions (although where supported by graphics hardware,
this is likely to be limited to single precision).

I must have been thinking about DirectX..

--
Bartc

```
 0
Reply bc (2337) 12/31/2011 11:29:03 AM

```"Keith Thompson" <kst-u@mib.org> ha scritto nel messaggio
news:lnlipvxe8b.fsf@nuthaus.mib.org...
> James Kuyper <jameskuyper@verizon.net> writes:
>> On 12/29/2011 02:03 PM, someone wrote:
>>> On Dec 29, 6:34 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
>>>> someone <newsbo...@gmail.com> wrote:
> [...]
>>>>> void setBezierPoint(const double &x, const double &y, const double &z,
>>>>>                     GLfloat bezierCTRpts[][3]) // 4th input is GONE !
>>>>> {
> [...]
> void setBezierPoint(double x, double y, double z,
>                    GLfloat bezierCTRpts[][3])
> {
> [...]
> }

here in the C++ case, i think, what is passed is a 32bit pointer each double arg
while in the C just above case is 64 bit double value, each double arg
so more data in the stack in the C case above

if in C++ i would use references in the case as above; something as

i32 setBezierPoint(GLfloat** bezierCTRptsRes, d64 &x, d64 &y, d64 &z) // 4th
input is GONE !

> --
> Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
>    Will write code for food.
> "We must do something.  This is something.  Therefore, we must do this."
>    -- Antony Jay and Jonathan Lynn, "Yes Minister"

```
 0

```Nobody <nobody@nowhere.com> writes:
> On Thu, 29 Dec 2011 11:03:46 -0800, someone wrote:
>
>> Of some reason, floats seem to be widely used with opengl... Don' ask
>> me why - I don't know.
>
> OpenGL itself either provides both float and double versions, or just a
> double version.
>
> Code which uses OpenGL tends to use double because the extra precision is
------
> usually either entirely pointless (if the hardware only uses single
> precision) or mostly pointless (any difference will be imperceptible), and
> tends to harm performance (twice the memory consumption, either twice or
> four times as many GPU cycles).

Did you mean "Code which uses OpenGL tends to use float ..."?

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
```
 0
Reply kst-u (21963) 12/31/2011 7:04:12 PM

```io_x=E6=96=BC 2011=E5=B9=B412=E6=9C=8831=E6=97=A5=E6=98=9F=E6=9C=9F=E5=85=
=93=EF=BC=9A
> "Keith Thompson" <ks...@mib.org> ha scritto nel messaggio
> news:lnlipvxe8b.fsf@nuthaus.mib.org...
> > James Kuyper <james...@verizon.net> writes:
> >> On 12/29/2011 02:03 PM, someone wrote:
> >>> On Dec 29, 6:34 pm, j....@toerring.de (Jens Thoms Toerring) wrote:
> >>>> someone <news...@gmail.com> wrote:
> > [...]
> >>>>> void setBezierPoint(const double &x, const double &y, const double =
&z,
> >>>>>                     GLfloat bezierCTRpts[][3]) // 4th input is GONE=
!
> >>>>> {
> > [...]
> > void setBezierPoint(double x, double y, double z,
> >                    GLfloat bezierCTRpts[][3])
> > {
> > [...]
> > }
>=20
> here in the C++ case, i think, what is passed is a 32bit pointer each dou=
ble arg
> while in the C just above case is 64 bit double value, each double arg
> so more data in the stack in the C case above
>=20
> if in C++ i would use references in the case as above; something as
>=20
> i32 setBezierPoint(GLfloat** bezierCTRptsRes, d64 &x, d64 &y, d64 &z) // =
4th
> input is GONE !
>=20

Doubles in the X86, Mips, ArmX,  Sh-XX, SparcX, LION from ESA=20
and  N-64 are all different.=20

But I think the 8 core Cell from IBM in PS3 can kill the strange NVIDIA GPA=
from the PC platform  if Sonny really wanted to do that.=20

Sonny sold some boards in  racks  of the Cell cores  in the movie industry,
and GPAS from NVIDIA were not useful at all.=20

Perhaps more subtle business concerns in the stock market were framed.=20

Japanese always diversify component suppliers in the long run.=20
=20
=20

=20
serious enough=20

> > --=20
> > Keith Thompson (The_Other_Keith) ks...@mib.org  <http://www.ghoti.net/~=
kst>
> >    Will write code for food.
> > "We must do something.  This is something.  Therefore, we must do this.=
"
> >    -- Antony Jay and Jonathan Lynn, "Yes Minister"

```
 0
Reply dihedral88888 (789) 12/31/2011 11:10:02 PM

```88888 Dihedral wrote:

> io_x? 2011?12?31????UTC+8??11?32?30???:
>> "Keith Thompson" <ks...@mib.org> ha scritto nel messaggio
>> news:lnlipvxe8b.fsf@nuthaus.mib.org...
>>> James Kuyper <james...@verizon.net> writes:
>>>> On 12/29/2011 02:03 PM, someone wrote:
>>>>> On Dec 29, 6:34 pm, j....@toerring.de (Jens Thoms Toerring) wrote:
>>>>>> someone <news...@gmail.com> wrote:
>>> [...]
>>>>>>> void setBezierPoint(const double &x, const double &y, const
>>>>>>>                     double &z, GLfloat bezierCTRpts[][3]) //
>>>>>>> 4th input is GONE ! {
>>> [...]
>>> void setBezierPoint(double x, double y, double z,
>>>                    GLfloat bezierCTRpts[][3])
>>> {
>>> [...]
>>> }
>>
>> here in the C++ case, i think, what is passed is a 32bit pointer
>> each double arg while in the C just above case is 64 bit double
>> value, each double arg
>> so more data in the stack in the C case above
>>
>> if in C++ i would use references in the case as above; something as
>>
>> i32 setBezierPoint(GLfloat** bezierCTRptsRes, d64 &x, d64 &y, d64
>> &z) // 4th input is GONE !
>>
>
> Doubles in the X86, Mips, ArmX,  Sh-XX, SparcX, LION from ESA
> and  N-64 are all different.
>
> But I think the 8 core Cell from IBM in PS3 can kill the strange
> NVIDIA GPA from the PC platform  if Sonny really wanted to do that.
>
> Sonny sold some boards in  racks  of the Cell cores  in the movie
> industry,
> and GPAS from NVIDIA were not useful at all.
>
> Perhaps more subtle business concerns in the stock market were framed.
>
> Japanese always diversify component suppliers in the long run.

A bird in the hand is worth two in the bush.

```
 0
Reply r124c4u1022 (2303) 1/1/2012 12:03:29 AM

```On Sat, 31 Dec 2011 11:04:12 -0800, Keith Thompson wrote:

>> Code which uses OpenGL tends to use double because the extra precision is
>                                       ------
>> usually either entirely pointless (if the hardware only uses single
>> precision) or mostly pointless (any difference will be imperceptible), and
>> tends to harm performance (twice the memory consumption, either twice or
>> four times as many GPU cycles).
>
> Did you mean "Code which uses OpenGL tends to use float ..."?

Yes. Either that or "... tends to avoid double ...".

```
 0
Reply nobody (5153) 1/1/2012 8:20:27 AM

```In article <0.dcfd9b0b4291e1147cd8.20111229203726GMT.87vcoz9ks9.fsf@bsb.me.uk>,
Ben Bacarisse  <ben.usenet@bsb.me.uk> wrote:
>The cast is superfluous.

Automatic conversion of 'double' to 'float' is one thing that i would
rather not have in the language.
```
 0
Reply jgk1 (251) 1/3/2012 3:48:20 PM

```jgk@panix.com (Joe keane) writes:

> In article <0.dcfd9b0b4291e1147cd8.20111229203726GMT.87vcoz9ks9.fsf@bsb.me.uk>,
> Ben Bacarisse  <ben.usenet@bsb.me.uk> wrote:
>>The cast is superfluous.
>
> Automatic conversion of 'double' to 'float' is one thing that i would
> rather not have in the language.

OK, but it's there, like it or not!  The cast might have been put there
to shut the compiler up, but from the style of the code I doubt it.  gcc
can be asked to warn about implicit demotions from double to float which
is the next best thing to not having them in the language.  If the cast
was added to silence this warning, then I'd say a comment is called for.
potentially lossy conversion.

--
Ben.
```
 0
Reply ben.usenet (6790) 1/3/2012 4:47:59 PM

```jgk@panix.com (Joe keane) writes:
> In article <0.dcfd9b0b4291e1147cd8.20111229203726GMT.87vcoz9ks9.fsf@bsb.me.uk>,
> Ben Bacarisse  <ben.usenet@bsb.me.uk> wrote:
> >The cast is superfluous.
>
> Automatic conversion of 'double' to 'float' is one thing that i would
> rather not have in the language.

Use your compiler flags to turn it into a warning, and turn warnings into
fatal errors?

Phil
--
Unix is simple. It just takes a genius to understand its simplicity
-- Dennis Ritchie (1941-2011), Unix Co-Creator
```
 0
Reply thefatphil_demunged (1650) 1/5/2012 8:31:24 PM

```someone <newsboost@gmail.com> writes:

> Hi all
>
> Noob question:
>
> -----------------------------------------------------------------------------
> typedef float GLfloat; // float = GLfloat
>
> void setBezierPoint(const double &x, const double &y, const double &z,
>                     const int &P, GLfloat bezierCTRpts[][3])
> {
>   bezierCTRpts[P][0] = (GLfloat)x;
>   bezierCTRpts[P][1] = (GLfloat)y;
>   bezierCTRpts[P][2] = (GLfloat)z;
> }
>
>
> void FindBezierControlPointsND(const int *N_kontur,
>       const double *cpp_X, const double *cpp_Y, GLfloat bezierData[]
> [3])
> {
>   // calculations...
>   // set xyz for point P=0 using 4th input parameter:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, 0, bezierData);
>
>   // set xyz for point P=3 using 4th input parameter:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, 3, bezierData);
> }
>
>
> int main(int argc, char** argv)
> {
>   cout << "hi" << endl;
>   GLfloat bezierData[4][3] = {0};
>
>   // something
>   FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);
> }
> -----------------------------------------------------------------------------
>
> Explanation:
>
> I have a static 2D array: bezierData[4][3], 4 points * xyz-coordinates
> and I pass it to FindBezierControlPointsND with this call:
>
>   FindBezierControlPointsND( &N_kontur, Xval, Yval, bezierData);
>
> and the function takes: GLfloat bezierData[][3] as input.
> All is ok - the code works, however what I really wanted was to omit
> the 4th input parameter (const int &P) so it looks like:
>
> void setBezierPoint(const double &x, const double &y, const double &z,
>                     GLfloat bezierCTRpts[][3]) // 4th input is GONE !
> {
>   bezierCTRpts[0][0] = (GLfloat)x;
>   bezierCTRpts[0][1] = (GLfloat)y;
>   bezierCTRpts[0][2] = (GLfloat)z;
> }
>
> Then I wanted to set the xyz-values by a function call like:
>
> - for P=0:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[0][0]);
>
> - for P=3:
>   setBezierPoint(cpp_X[0], cpp_Y[0], 0.0, bezierData[3][0]);
>
>
> This however doesn't work! I also tried to add "&" in front of
> bezierData[3][0] etc... Error message is something like:
>
> error: cannot convert 'GLfloat* {aka float*}' to 'GLfloat* (*)[3] {aka
> float* (*)[3]}' for argument '4' to 'void setBezierPoint(const
> double&, const double&, const double&, GLfloat* (*)[3])'

1. What is the type of the expression     bezierData[0][0]?

2. What is the type of the expression    &bezierData[0][0]?

3. What is the type of the expression     bezierData[0]?

4. What is the type of the expression    &bezierData[0]?

4. What is the type of the expression     bezierData?

5. What is the type of the expression    &bezierData?

and finally

6. What is the type of the parameter      bezierCTRpts?

If you can answer these questions I believe you will
discover a solution to your problem.

> If you like/ask for it, perhaps I can make a minimal working example.

That's a good idea, not just because it helps people on
the newsgroup, but if you do there is a good chance you'll

> However, I hope one of you geniuses out there can spot my mistake
> right on :-)

Spotting the mistake is fairly easy.  What's harder is
figuring out what makes it unclear to someone asking
the question and how to explain it to them.
```
 0
Reply txr1 (1479) 1/26/2012 1:39:09 AM

```Keith Thompson <kst-u@mib.org> writes:

> someone <newsboost@gmail.com> writes:
>> On Dec 29, 6:34 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
>>> someone <newsbo...@gmail.com> wrote:
>>>
>>> Please note that your code is C++ while this is a C newsgroup.
>>
>> Maybe 1% C++ and 99% C, ok.
>
> There's a term for code that's 1% CZ++ and 99% C.  We call it "C++".
>
> There are at least 2 C++-specific things in your code: the parameters of
> setBezierPoint are C++ references, and you use "cout << ..." in main().
>
> And even if those are corrected, you have no declaration for N_kontur,
> Xval, or Yval.
>
> It's not a *huge* deal, but for future reference it's best to post
> straight C code here.  Compile it with a C compiler and copy-and-paste
> the exact code that you compiled.  Otherwise, it can be difficult to
> tell whether your problems are C++-specific and/or whether they're
> related to errors you made when you re-typed the code.

I think this reaction is somewhat harsh.  Despite the code
having some C++ aspects, the issue underlying the question
is fairly obviously a C question, so someone here should
have been able to help him.  What's more, it seems plausible
that the problem he was having is something that C people
would be better at than C++ people, in which case sending
him over to comp.lang.c++ would have hurt rather than
helped.  I don't think that's what you want.
```
 0
Reply txr1 (1479) 1/26/2012 1:45:08 AM

```Seebs <usenet-nospam@seebs.net> writes:

> On 2011-12-29, someone <newsboost@gmail.com> wrote:
>>> You are looking fro comp.lang.c++.
>
>> No I'm not.
>
> I'm curious as to why you say this.  Your code is obviously C++.  Nothing
> similar to it has ever been part of C.
>
> Granted that a similar question could apply to C, the mere fact that you're
> using references means that the rules for what you're doing are certainly
> going to be different.
>
> So the question is:  Why *aren't* you looking for a C++ group?  Do you think
> that they would be unable to answer your question?  If so, why?

Just a question here.  Did you look at all at the problem
he was having and try to decide if it was C related or
C++ related?  I agree that the code is clearly C++ code;
but did you do any looking past that initial impression?
I'm just curious.
```
 0
Reply txr1 (1479) 1/26/2012 1:47:55 AM

```On 2012-01-26, Tim Rentsch <txr@alumni.caltech.edu> wrote:
> have been able to help him.  What's more, it seems plausible
> that the problem he was having is something that C people
> would be better at than C++ people, in which case sending
> him over to comp.lang.c++ would have hurt rather than
> helped.  I don't think that's what you want.

Also, maybe it's a dialect of C which has C++-like references.

Jacob Navia's Lcc-Win32 has references.

If such a dialect doesn't have a more specific newsgroup of its own,
comp.lang.c is it.
```
 0
Reply kaz15 (1143) 1/26/2012 2:08:58 AM

35 Replies
99 Views

Similar Articles

12/8/2013 3:16:22 PM
[PageSpeed]