C++ and Motif - Help Compiling Code - Motif

This is a discussion on C++ and Motif - Help Compiling Code - Motif ; Dear Readers, I am attempting to compile so Motif code using a c++ compiler. The code is roughly based on Dan Hellers book examples for building menus. When I try to compile the code I get the following error message. ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: C++ and Motif - Help Compiling Code

  1. C++ and Motif - Help Compiling Code

    Dear Readers,

    I am attempting to compile so Motif code using a c++ compiler. The
    code
    is roughly based on Dan Hellers book examples for building menus.

    When I try to compile the code I get the following error message.

    Could it be explained what is wrong here. Note I only have a cxx
    complier,
    but I do not want to write code that will not work with standard c as
    well. Sorry poor english.

    I am using Open VMS 6.2 and cxx compiler.

    Thanks

    Tanaka.

    ALPHA >cxx test.c

    {"File", (XtCallbackProc) callback, (XtPointer) 0, NULL},
    .............^
    %CXX-E-PTRMISMATCH, In the initializer for
    Menus[0]._menu_item::callback, the
    referenced type of the pointer value "(XtCallbackProc)callback" is
    "function
    (pointer to _WidgetRec, pointer to void, pointer to void) returning
    void░G ╩x╚<
    at line number 33 in file TEST.C

    #include
    #include
    #include
    #include

    typedef struct _menu_item
    {
    char *label;
    XtCallbackProc (*callback)();
    XtPointer callback_data;
    struct _menu_item *subitems;
    } MenuItem;


    void Addcallback(Widget parent, MenuItem *items)
    {
    int i;
    for (i = 0; items[i].label != NULL; i++)
    {
    if (items[i].callback)
    XtAddCallback(parent, XmNactivateCallback,
    (XtCallbackProc) items[i].callback, items[i].callback_data);
    }
    }

    void callback (Widget w, XtPointer clientdata, XtPointer calldata)
    {

    }

    MenuItem Menus[] =
    {
    {"File", (XtCallbackProc) callback, (XtPointer) 0, NULL},
    NULL,
    };

  2. Re: C++ and Motif - Help Compiling Code

    Hiroyuki Tanaka wrote:

    > Dear Readers,
    >
    > I am attempting to compile so Motif code using a c++ compiler. The
    > code
    > is roughly based on Dan Hellers book examples for building menus.
    >
    > When I try to compile the code I get the following error message.
    >
    > Could it be explained what is wrong here. Note I only have a cxx
    > complier,
    > but I do not want to write code that will not work with standard c as
    > well. Sorry poor english.
    >
    > I am using Open VMS 6.2 and cxx compiler.
    >
    > Thanks
    >
    > Tanaka.
    >
    > ALPHA >cxx test.c
    >
    > {"File", (XtCallbackProc) callback, (XtPointer) 0, NULL},
    > ............^
    > %CXX-E-PTRMISMATCH, In the initializer for
    > Menus[0]._menu_item::callback, the
    > referenced type of the pointer value "(XtCallbackProc)callback" is
    > "function
    > (pointer to _WidgetRec, pointer to void, pointer to void) returning
    > void░G ╩x╚<
    > at line number 33 in file TEST.C
    >
    > #include
    > #include
    > #include
    > #include
    >
    > typedef struct _menu_item
    > {
    > char *label;
    > XtCallbackProc (*callback)();


    XtCallbackProc is already typedef'ed as a function pointer. Use plain:

    XtCallbackProc callback;

    > XtPointer callback_data;
    > struct _menu_item *subitems;
    > } MenuItem;
    >
    >
    > void Addcallback(Widget parent, MenuItem *items)
    > {
    > int i;
    > for (i = 0; items[i].label != NULL; i++)
    > {
    > if (items[i].callback)
    > XtAddCallback(parent, XmNactivateCallback,
    > (XtCallbackProc) items[i].callback, items[i].callback_data);
    > }
    > }
    >
    > void callback (Widget w, XtPointer clientdata, XtPointer calldata)
    > {
    >
    > }
    >
    > MenuItem Menus[] =
    > {
    > {"File", (XtCallbackProc) callback, (XtPointer) 0, NULL},
    > NULL,
    > };


    HaND,
    --
    Michel Bardiaux
    Peaktime Belgium S.A. Bd. du Souverain, 191 B-1160 Bruxelles
    Tel : +32 2 790.29.41


  3. Re: C++ and Motif - Help Compiling Code

    > typedef struct _menu_item
    > {
    > char *label;
    > XtCallbackProc (*callback)();
    > XtPointer callback_data;
    > struct _menu_item *subitems;
    > } MenuItem;


    You appear to be declaring callback as a pointer to a function
    taking no parameters and returning an XtCallbackProc function.
    Shouldn't this be:

    XtCallbackProc callback;

    or is it:

    XtCallbackProc *callback;

    Also, when you declare the callback function don't you need to
    declare it as extern "C" to make sure it has C linkage rather
    than C++.

    Martin Kirby

+ Reply to Thread