[comp.windows.x] X11 and C++

rfg@ics.uci.edu (Ronald Guilmette) (02/14/90)

In article <943@imec.UUCP> depuydt@imec.be (Francis Depuydt) writes:
>I would like to use the X11 library functions in my C++ environment.
>However, some keywords of C++ seem to be used for X11 variables. 
>Are there other incompatibilities? Did some of you experience the same
>sort of problem, and what is the 'cheapest' solution?

I have been encouraging the folks at MIT Project Athena and at
the X Consortium to use my protoize and unprotoize tools to whip X11
into condition so that individual end-users could easily generate their
own fully-prototyped versions of X11 (and especially its include files).

There seems to some interest in doing this at both places, but that interest
is tempered by resource (i.e. manpower) limitations.

Regardless of that, I hope that we will all someday enjoy an "easily
protoizable" version of X11.

// rfg

jlv@cs.brown.edu (Jeff Vogel) (02/14/90)

In article <25D887FF.273@paris.ics.uci.edu> rfg@ics.uci.edu (Ronald Guilmette) writes:
>In article <943@imec.UUCP> depuydt@imec.be (Francis Depuydt) writes:
>>I would like to use the X11 library functions in my C++ environment.
>>However, some keywords of C++ seem to be used for X11 variables. 
>>Are there other incompatibilities? Did some of you experience the same
>>sort of problem, and what is the 'cheapest' solution?
>

I am all for some tools to let X11 compile with C++.
Incidentally, how did you solve the type checking problem?
Did you create your own header files with all of the
X extern declarations and their parameters (or ...).

  Jeff Vogel                      |  PO Box 5173        
  jlv@cs.brown.edu                |  Brown University    
  uunet!brunix!jlv                |  Providence, RI 02912
  jlv@browncs.bitnet              |  401-863-7637, 401-421-6496 

sdm@cs.brown.edu (Scott Meyers) (02/14/90)

The X11R4 header files come with C++ declarations already in them.  For
example, this is from Xlib.h:

    #ifdef __cplusplus			/* do not leave open across includes */
    extern "C" {					/* for C++ V2.0 */
    #endif

I don't do X programming myself, so I can't vouch for how well the new
include files work with C++ (the distribution documentation says the
support isn't part of the official standard yet), but I know at least one
person doing X programming who's used the headers with cfront 2.0 without
any problems.

Scott
sdm@cs.brown.edu

rfg@ics.uci.edu (Ronald Guilmette) (02/15/90)

In article <29158@brunix.UUCP> jlv@cs.brown.edu (Jeff Vogel) writes:
>In article <25D887FF.273@paris.ics.uci.edu> rfg@ics.uci.edu (Ronald Guilmette) writes:
>>In article <943@imec.UUCP> depuydt@imec.be (Francis Depuydt) writes:
>>>I would like to use the X11 library functions in my C++ environment.
>>>However, some keywords of C++ seem to be used for X11 variables. 
>>>Are there other incompatibilities? Did some of you experience the same
>>>sort of problem, and what is the 'cheapest' solution?
>>
>
>I am all for some tools to let X11 compile with C++.
>Incidentally, how did you solve the type checking problem?
>Did you create your own header files with all of the
>X extern declarations and their parameters (or ...).

I guess that I should have been posting my announcements of protoize &
unprotoize tools to the comp.windows.x newsgroup also!  Some people
have obviously missed them!

Let me now SHOUT so that ****** EVERYONE ON THE NET CAN HEAR ME *******

There are free tools available (called protoize & unprotoize) which are
ultra intelligent tools that use information from your C code source files
(that is, both "base" files *and* include files) to convert entire *large*
system of K&R C source code (e.g. X11) from good old K&R C code to
fully prototyped ANSI C code (or to C++ code).

The protoize tool cannot possibly do a full-fledged conversion (too many
nit-picking details) but it will do all necessary conversion of
function declarations and definitions (in both base files and include
files) to prototype format.  This work constitutes the bulk of the
conversion effort.  Other tweeking must be done manually, but protoize
can typically do better than 90% of the editing work.

A critically important feature of protoize is that it obtains information
to do its job from *all* of the files in a given program before it even
starts its work.  This allows it to do intelligent conversion of function
declarations and definitions even across multiple files (and in particular
into include files).

For example, assume the following files:

    foo.h:
	-----------------------------------------------------------------
	extern int bar ();
	-----------------------------------------------------------------

    foo.c:
	-----------------------------------------------------------------
	int bar ();

	typedef struct tricky_case *tricky_p;

	int bar (i, p)
	    int i;
	    tricky_p p;
	{
		...
	}
	-----------------------------------------------------------------

After running protoize over these files, they come out looking like this:

    foo.h:
	-----------------------------------------------------------------
	extern int bar (int i, tricky_p p);
	-----------------------------------------------------------------

    foo.c:
	-----------------------------------------------------------------
	int bar (int i, tricky_p p);

	typedef struct tricky_case *tricky_p;

	int bar (int i, tricky_p p)
	{
		...
	}
	-----------------------------------------------------------------

Now you must manually move the typedef for `tricky_p' up into the include
file, but there are some people (me included) who would say that good
software engineering practices would make you want to do this anyway.
After all, if there is a declaration of `bar' in the include file
(where it is presumably needed because other files may need to make
references to `bar') then by all rights, these other files will
probably also need to know about the type called `tricky_p'.

Anyway, as you should see from the above example, protoize is capable of
automatically generating a fully prototyped set of include files for
any large system of old-style (K&R) C code (e.g. X11).  Of course,
as I have said, there may be a bit of tweeking required afterwards
to get these files back into a "legal" form.

Protoize/Unprotoize use the GNU C compiler as a "front-end" information
gathering tool.  (Thus I didn't have to build a whole darn parser!)
You must have GCC to make use of protoize/unprotoize.

Protoize/Unprotoize (v1.07) are available via anonymous FTP from
ics.uci.edu. look for the file protoize-1.07.Z in the ~ftp/pub
directory.  This is a compressed *patch* file (not a tar file).
It must be applied to GCC 1.36.  You then must rebuild GCC and read
the supplied man pages for protoize/unprotoize.

Protoize/Unprotoize 1.07 is also available via anonymous UUCP from osu-cis.

I case it ain't obvious, I hope that everyone will convert to using
prototypes someday real soon.

// rfg

csmoe@mtsu.EDU (Miss. Monisha Guglani) (10/05/90)

Hi,
	I'm sorry if this has come up before or if anyone has
	a already posted a solution to this 
	I'm trying to use the Xlib files to be included in C++
	and because of the declaration of class as an integer within 
	the Xlib I have a bunch of errors . (Class is reserved word in c++)
	Is there another Xlib out there for use with C++ or is there
	a simple way to work around this problem!!
-- 
/**************************************************************/
/*       csmoe@knuth.mtsu.edu        Monisha Guglani          */	   
/* "I haven't lost my mind its backed-up on a tape somewhere" */
/**************************************************************/

klee@wsl.dec.com (Ken Lee) (10/06/90)

In article <m0iKbY9-00049YC@knuth.mtsu.edu>, csmoe@mtsu.EDU (Miss. Monisha Guglani) writes:
|> 	I'm trying to use the Xlib files to be included in C++
|> 	and because of the declaration of class as an integer within 
|> 	the Xlib I have a bunch of errors . (Class is reserved word in c++)

The X11R4 Xlib has stuff like this in it:

#if defined(__cplusplus) || defined(c_plusplus)
        int c_class;            /* C++ class of screen (monochrome, etc.) */
#else
        int class;              /* class of screen (monochrome, etc.) */
#endif

so using it with C++ shouldn't be a problem.

-- 
Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee

soh@shiva.trl.oz (kam hung soh) (10/09/90)

klee@wsl.dec.com (Ken Lee) writes:
>In article <m0iKbY9-00049YC@knuth.mtsu.edu>, csmoe@mtsu.EDU (Miss. Monisha Guglani) writes:
>|> 	I'm trying to use the Xlib files to be included in C++

>The X11R4 Xlib has stuff like this in it:

>#if defined(__cplusplus) || defined(c_plusplus)
>        int c_class;            /* C++ class of screen (monochrome, etc.) */
>#else
>        int class;              /* class of screen (monochrome, etc.) */
>#endif

>so using it with C++ shouldn't be a problem.

I would like to add that those constants are turned on for the AT&T
cfront.  I believe the C++ stuff from MIT was tested with cfront
2.0

-----
Soh, Kam Hung      email: h.soh@trl.oz.au     tel: +61 03 541 6403 
Telecom Research Laboratories, P.O. Box 249, Clayton, Victoria 3168, Australia