[comp.windows.x] trouble with X11r4 prototyping

aed@netcom.COM (Andrew Davidson) (04/05/91)

Hi

Here is a little X program I can not seem to get to compile. I am trying to
use the sun c++ compiler. (This code is really just normal C code) I should
note that it compiles and runs with out any problem when I use gnu g++
1.37.1. But does not compile when I use the sun c++ compiler (basic AT&T c++
compiler)

I am using X11r4 and motif 1.1
Thanks in advance
-------------------- compiler error messages -----------------
CC -c -g -I../../libxs main.cc
CC  +g main.cc:
"main.cc", line 42: error:
    bad argument  3 type for XtAddCallback():
    void (*)(Widget , caddr_t ,
    XmAnyCallbackStruct *) ( XtCallbackProc  expected)
1 error
cc   -c -I/usr2/CC/sun4/incl -I../../libxs  -g

------------------------------ code -------------------------------
#define XTFUNCPROTO 0       /*
                             * something is wrong
                             * I did not have to define this for g++
                             * I should not have to define this,
                             * see /usr/include/X11/Intrinsic.h
                             */
#include <math.h>
#include <iostream.h>       /* for g++ use stream.h */
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/PushB.h>
#include <Xm/Label.h>

void DoLotsOfWork(Widget w, caddr_t junk, XmAnyCallbackStruct *callData);

int main( int argc, char *argv[])
{
  Widget toplevel, button;

  toplevel = XtInitialize(argv[0], "BadClient", 0, 0, (Cardinal *)&argc,
                          argv);

  Arg wargs[10];
  int n = 0;
  XmString label = XmStringCreate("Do Lots of WORK!",
                                  XmSTRING_DEFAULT_CHARSET);
  XtSetArg(wargs[n], XmNlabelString, label); n++;
  button = XtCreateManagedWidget("button", xmPushButtonWidgetClass,
                                  toplevel, wargs, n);
/* 42 */  XtAddCallback(button, XmNactivateCallback, DoLotsOfWork, NULL);

  XtRealizeWidget(toplevel);
  XtMainLoop();
}

/*
 * this function prints its starting and ending time to cout
 * in general it does nothing special, just smokes lots of cycles
 */
void DoLotsOfWork(Widget w, caddr_t junk, XmAnyCallbackStruct *callData)
{
  long clock;

  /* but these lines in to nock out warnings */
  Widget g = w;
  caddr_t h = junk;
  XmAnyCallbackStruct *j = callData;

  time(&clock);
  cout << "BadClient starting time: " << ctime(&clock) << "\n";

  for (long i = 0; i < 60000; i++)
    pow(2.375, 2.375);

  time(&clock);
  cout << "BadClient ending time:   " << ctime(&clock) << "\n";
}

--------------------------- end code -----------------------------

-- 
-----------------------------------------------------------------
                  "bede-bede-bede Thats all Folks"
				Porky Pig
Andy Davidson
Woodside CA.
aed@netcom.COM
-----------------------------------------------------------------