Next: Lines 2 and Up: Explanation of the Previous: Explanation of the

Line 1

The first line of the program is extremely important. It initializes all of X and motif for you, gets your main application window set up, etc.:


          toplevel=XtInitialize(argv[0],"",NULL,0,&argc,argv);

It accepts several parameters. The first one is the name of the application. Since argv[0] contains the name used to execute the command, it is used here.

The second parameter is the name of a "resource file" that can be loaded. We'll talk about resource files a little later, but they are text files of resource values that are used to customize applications. Resource values can be hard-coded into a program, or read in from resource files.

I have never had occasion to use the third and fourth parameters, so I just always use NULL and 0 for them. They have to do with command line parsing.

The last two parameters are argc and argv. Because xtInitialize extracts the command line arguments that relate to X but leaves the rest of them, it has to be able to change argc. You MUST pass argc and argv - 0 and NULL cannot be used. Be sure you use the ADDRESS of argc, since argc is changed by XtInitialize.

That's the initilization line. It should be the first line of all of your Motif programs. But it is easy to mess it up. Note that ALL of the following will cause a segmentation fault (you don't even get a core!) and can be very hard to track down:


          toplevel=XtInitialize(argv[0],NULL,NULL,0,&argc,argv);
          toplevel=XtInitialize(argv[0],"",NULL,0,0,NULL);
          toplevel=XtInitialize(NULL,"",NULL,0,&argc,argv);
          toplevel=XtInitialize(argv[0],"",NULL,0,argc,argv);

This is true of most Motif functions - you must pass them exactly what they expect to see.


morbe@enstb.enst-bretagne.fr