Compiler problem

I’m trying to compile a few lines of code. They are really very simple,
but, with the C++ compiler set on maximum warning level I can’t product a
syntax that it will accept.

Here is some pseudo code:

void fn_that_works_on_a_widget( PtWidget_t * wp );
PtWidget_t * wp1;
PtWidget_t * wp2;
PtWidget_t * wp3;
PtWidget_t * wp4;
// The 4 widget pointers are properly initialized.
PtWidget_t * * my_widgets [ ] = { &wp1, &wp3, &wp2, &wp4 };
int selected_widget = 0; // 0 through 3

int my_callback( Pt_Widget_t *, ApInfo_t *, PtCallbackInfo_t )
{
// this next line is the line that won’t compile
fn_that_works_on_a_widget( *my_widgets[ selected_widget ] );
}

I’ve tried all kinds of convoluted lines with parentheses and typedef’s and
running the green magic marker around the outer edge of the CD. Nothing
seems to help.

What needs to be typecast differently?

Previously, you (Bill Caroselli (Q-TPS)) wrote:

I’m trying to compile a few lines of code. They are really very simple,
but, with the C++ compiler set on maximum warning level I can’t product a
syntax that it will accept.

Here is some pseudo code:

void fn_that_works_on_a_widget( PtWidget_t * wp );
PtWidget_t * wp1;
PtWidget_t * wp2;
PtWidget_t * wp3;
PtWidget_t * wp4;
// The 4 widget pointers are properly initialized.
PtWidget_t * * my_widgets [ ] = { &wp1, &wp3, &wp2, &wp4 };
int selected_widget = 0; // 0 through 3

int my_callback( Pt_Widget_t *, ApInfo_t *, PtCallbackInfo_t )
{
// this next line is the line that won’t compile
fn_that_works_on_a_widget( *my_widgets[ selected_widget ] );
}

I’ve tried all kinds of convoluted lines with parentheses and typedef’s and
running the green magic marker around the outer edge of the CD. Nothing
seems to help.

What needs to be typecast differently?

No typecasts needed - just remove the ‘*’ in front of ‘my_widgets[…]’ in
the line in question. That way, You will actually pass a widget pointer,
not try to pass a complete widget structure. In other words, my_widgets is
an array of widget pointers, and fn_that_works_on_a_widget expects a widget
pointer. So taking one element from my_widgets using [] gives You exactly
what the function wants.

Regards,


T. Haupt

BitCtrl Systems GmbH
Weissenfelser Str. 67
04229 Leipzig

Phone: +49 (0)341 49067 0
Phax: +49 (0)341 49067 15
eMail: frk bitctrl de

Thanks, but no cigar.

That results in:
Warning! W007 “&array” may not produce intended results
Error! E473 function arguments don’t match those in prototype
Note! N630 source conversion type is “Pt_widget * * &”
Note! N631 target conversion type is “Pt_widget *”

But I found that one of the things I tried that resulted in an error was
complaining about a different error. I found and fixed the other error and
now it compiles.

“Thomas Haupt” <frk@bitctrl.de> wrote in message
news:Voyager.020814073942.256B@qnxserver.bitctrl

Previously, you (Bill Caroselli (Q-TPS)) wrote:

void fn_that_works_on_a_widget( PtWidget_t * wp );
PtWidget_t * wp1;
PtWidget_t * wp2;
PtWidget_t * wp3;
PtWidget_t * wp4;
// The 4 widget pointers are properly initialized.
PtWidget_t * * my_widgets [ ] = { &wp1, &wp3, &wp2, &wp4 };
int selected_widget = 0; // 0 through 3

int my_callback( Pt_Widget_t *, ApInfo_t *, PtCallbackInfo_t )
{
// this next line is the line that won’t compile
fn_that_works_on_a_widget( *my_widgets[ selected_widget ] );
}

What needs to be typecast differently?

No typecasts needed - just remove the ‘*’ in front of ‘my_widgets[…]’ in
the line in question. That way, You will actually pass a widget pointer,
not try to pass a complete widget structure. In other words, my_widgets is
an array of widget pointers, and fn_that_works_on_a_widget expects a
widget
pointer. So taking one element from my_widgets using [] gives You exactly
what the function wants.

Regards,

“Bill Caroselli (Q-TPS)” <QTPS@earthlink.net> wrote:

I’m trying to compile a few lines of code. They are really very simple,
but, with the C++ compiler set on maximum warning level I can’t product a
syntax that it will accept.

I fixed a couple of typos in your code and added a return statement and
it compiled with no warnings. Here’s my version of the code:

#include <Pt.h>
#include <Ap.h>

void fn_that_works_on_a_widget( PtWidget_t * wp );
PtWidget_t * wp1;
PtWidget_t * wp2;
PtWidget_t * wp3;
PtWidget_t * wp4;
// The 4 widget pointers are properly initialized.
PtWidget_t * * my_widgets [ ] = { &wp1, &wp3, &wp2, &wp4 };
int selected_widget = 0; // 0 through 3

int my_callback( PtWidget_t *, ApInfo_t *, PtCallbackInfo_t * )
{
// this next line is the line that won’t compile
fn_that_works_on_a_widget( *my_widgets[ selected_widget ] );
return Pt_CONTINUE;
}

If it generates warnings for you, what are the warnings?


Wojtek Lerch QNX Software Systems Ltd.

Previously, you (Bill Caroselli (Q-TPS)) wrote:

Thanks, but no cigar.

That results in:
Warning! W007 “&array” may not produce intended results
Error! E473 function arguments don’t match those in prototype
Note! N630 source conversion type is “Pt_widget * * &”
Note! N631 target conversion type is “Pt_widget *”

But I found that one of the things I tried that resulted in an error was
complaining about a different error. I found and fixed the other error and
now it compiles.
snip

Sorry, I didn’t notice You had an array of widget **s - thought it was
merely an array of *s. Please accept my excuses for the inappropriate help.

Regards,


T. Haupt