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

Discussion in 'C Programming' started by someone, Dec 29, 2011.

1. someoneGuest

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])’

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!

someone, Dec 29, 2011

2. Ben BacarisseGuest

someone <> 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.

Ben Bacarisse, Dec 29, 2011

3. Jens Thoms ToerringGuest

someone <> 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 ___
\__________________________ http://toerring.de

Jens Thoms Toerring, Dec 29, 2011
4. Barry SchwarzGuest

On Thu, 29 Dec 2011 09:11:08 -0800 (PST), someone
<> 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

Barry Schwarz, Dec 29, 2011
5. someoneGuest

Re: passing static 2D array to function - not fully working like Ihoped for...

On Dec 29, 6:27 pm, Ben Bacarisse <> wrote:
> someone <> 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.

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:

>
> >   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.

Aaah, thank you very much!

>   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.

Thank you!

> > 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]);

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.  Have 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

someone, Dec 29, 2011
6. someoneGuest

Re: passing static 2D array to function - not fully working like Ihoped for...

On Dec 29, 6:34 pm, (Jens Thoms Toerring) wrote:
> someone <> 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:
> >   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;
>
> }

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=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.

That's great Jens. Thank you very much. Appreciate your help and
time...

someone, Dec 29, 2011
7. someoneGuest

Re: passing static 2D array to function - not fully working like Ihoped for...

On Dec 29, 6:49 pm, Barry Schwarz <> wrote:
> On Thu, 29 Dec 2011 09:11:08 -0800 (PST), someone
>
> <> 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++.

No I'm not.

someone, Dec 29, 2011
8. SeebsGuest

Re: passing static 2D array to function - not fully working like Ihoped for...

On 2011-12-29, someone <> 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 /
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.

Seebs, Dec 29, 2011
9. Jens Thoms ToerringGuest

someone <> wrote:
> On Dec 29, 6:34Â pm, (Jens Thoms Toerring) wrote:
> > someone <> 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 ___
\__________________________ http://toerring.de

Jens Thoms Toerring, Dec 29, 2011
10. Keith ThompsonGuest

someone <> writes:
> On Dec 29, 6:34Â pm, (Jens Thoms Toerring) wrote:
>> someone <> 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) <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"

Keith Thompson, Dec 29, 2011
11. James KuyperGuest

Re: passing static 2D array to function - not fully working likeI hoped for...

On 12/29/2011 02:03 PM, someone wrote:
> On Dec 29, 6:34 pm, (Jens Thoms Toerring) wrote:
>> someone <> 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.

James Kuyper, Dec 29, 2011
12. Ben BacarisseGuest

someone <> writes:

> On Dec 29, 6:34Â pm, (Jens Thoms Toerring) wrote:
>> someone <> 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.

Ben Bacarisse, Dec 29, 2011
13. Keith ThompsonGuest

James Kuyper <> writes:
> On 12/29/2011 02:03 PM, someone wrote:
>> On Dec 29, 6:34 pm, (Jens Thoms Toerring) wrote:
>>> someone <> 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) <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"

Keith Thompson, Dec 29, 2011
14. someoneGuest

Re: passing static 2D array to function - not fully working like Ihoped for...

On Dec 29, 8:22 pm, Seebs <> wrote:
> On 2011-12-29, someone <> 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.

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:  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.
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.

someone, Dec 29, 2011
15. SeebsGuest

Re: passing static 2D array to function - not fully working like Ihoped for...

On 2011-12-29, someone <> 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 /
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.

Seebs, Dec 29, 2011
16. Keith ThompsonGuest

someone <> writes:
> On Dec 29, 8:22Â pm, Seebs <> 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) <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"

Keith Thompson, Dec 29, 2011
17. BartCGuest

"Jens Thoms Toerring" <> wrote in message
news:-berlin.de...
> someone <> 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

BartC, Dec 29, 2011
18. someoneGuest

Re: passing static 2D array to function - not fully working like Ihoped for...

On Dec 29, 10:42 pm, Seebs <> wrote:
> On 2011-12-29, someone <> 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++?

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 questions

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 actually
> writing C++, you're gonna get burned on the differences, which people maynot
> think to bring up.

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

> 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.

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]

someone, Dec 29, 2011
19. James KuyperGuest

Re: passing static 2D array to function - not fully working likeI hoped for...

On 12/29/2011 02:22 PM, Seebs wrote:
> On 2011-12-29, someone <> 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?

James Kuyper, Dec 29, 2011
20. SeebsGuest

Re: passing static 2D array to function - not fully working like Ihoped for...

On 2011-12-29, James Kuyper <> 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 /
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.

Seebs, Dec 30, 2011