[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

754.0. "C++ & DECwindows HELP!!" by PRSIS4::STRAUSS () Wed May 10 1989 10:52

    Although this continues from the topic I started previously (no.744)
    I decided to start a new topic because my problem might lead on
    to further discussion of the subject.
    
    I am currently trying to carry out some simple (!) programming using
    DECwindows and C++. I decided not to use any of the features of
    the DECwindows or X toolkits, but to use the functions of Xlib.
    
    The program I am currently working on - or should I say having
    difficulty with, is supposed to just open a window in which the user
    can draw lines by moving the mouse. 
    
    On compilation, however, all the Xlib functions used are rejected
    with compilation warnings stating:
    
    	The declaration for (Xlib function) was not specified
    
    My problem is that I don't understand why. I have a working version
    of the program that was written using traditional C. The main difference
    in the C++ version is that I have created a class called
    graphics_window and then created an instance of this class. The
    previous functions to enable the drawing of lines in the window
    thus becoming member functions of the graphics_window class.
    
    I realise that my program may not be elegant or efficient, but any
    help from anyone who has had success in programming DECwindows with
    C++ would be greatly appreciated.
    
    
#include <stdio.h>    
#include <prseac$dub2:[strauss.cpp.cpplib]Xlib.h>
#include <prseac$dub2:[strauss.cpp.cpplib]Xutil.h>

Display *dpy;
Screen *scr;

class graphics_window {
	Window			id;
	int			x,y,width,height;
	XSizeHints 		xsh;
	GC			gc;
	XGCValues		xgcv;
	XSetWindowAttributes	xswa;
	struct 
	  LastPoint {
		int X,Y;
		    }		last_pt;

public:
	graphics_window();
	void do_handle_events();
	void do_motion_notify(XEvent*);
	void do_button_press(XEvent*);
	void do_set_last_point(int, int);
	void do_draw_from_last_point(int, int);
};

graphics_window::graphics_window()
{
	width  = 500;
	height = 500;
	x      = 50;
	y      = 50;

	xswa.event_mask = ExposureMask |
			  ButtonPressMask |
			  Button3MotionMask ;

	xswa.background_pixel = XBlackPixelOfScreen;

        id = XCreateWindow(dpy, XRootWindowOfScreen(scr), 
			    x, y, width, height,		   
		            0, XDefaultDepthOfScreen(scr), 
			    InputOutput,
			    XDefaultVisualOfScreen(scr),
			    CWEventMask | CWBackPixel, &xswa);

	XStoreName(dpy, id, "If this doesn't bloody work this time...");

	xgcv.foreground = XWhitePixelOfScreen;
	xgcv.background = XBlackPixelOfScreen;
	xgcv.line_width = 3;
        xgcv.line_style = LineSolid;
	xgcv.cap_style  = CapButt;
	xgcv.join_style = JoinMiter;

	gc = XCreateGC(dpy, id, GCForeground | GCBackground |
 			GCLineWidth | GCLineStyle | GCCapStyle |
			 GCJoinStyle, &xgcv);

	xsh.x = 50;		
	xsh.y = 50;	
	xsh.width = 500;
	xsh.height = 500;
	xsh.flags = PPosition | PSize;

	XSetNormalHints(dpy, id, &xsh);

	XMapWindow(dpy, id);
}

void graphics_window::do_set_last_point(int X, int Y)
{
	last_pt.X = X;
	last_pt.Y = Y;
}

void graphics_window::do_draw_from_last_point(int X, int Y)
{
	XDrawLine(dpy, id, gc, last_pt.X, last_pt.Y, X, Y);
}

void graphics_window::do_motion_notify(XEvent *eventP)
{
	if (eventP->xmotion.state = Button3Mask)
		{
			last_pt.X = eventP->xmotion.x;
			last_pt.Y = eventP->xmotion.y;

			do_draw_from_last_point(last_pt.X, last_pt.Y);
			do_set_last_point(last_pt.X, last_pt.Y);
		}
	return;
}

void grphics_window::do_button_press(XEvent *eventP)
{
	last_pt.X = (eventP->xbutton.x);
	last_pt.Y = (eventP->xbutton.y);

	unsigned int but = eventP->xbutton.button;

	if (but != Button1)
		{
		switch (but)
		{
			case Button2:
			     do_set_last_point(last_pt.X, last_pt.Y);	
			     return;

			case Button3:
                             do_draw_from_last_point(last_pt.X, last_pt.Y);
			     return;
		}
		}

	XUnmapWindow(dpy, id);
	XDestroyWindow(dpy, id);

	XCloseDisplay(dpy);

	exit(1);
}

void graphics_window::do_handle_events()
{
	XEvent event;

	for ( ; ; )
		{
			XNextEvent(dpy, &event);
			switch (event.type)
			{
				case MotionNotify:
					do_motion_notify(&event); break;

				case ButtonPress:
					do_button_press(&event); break;
			}
		}
}


static int main()
{
	dpy = XOpenDisplay(0);

	if (!dpy) { printf("Display not opened !\n"); }

	scr = XDefaultScreenOfDisplay(dpy);

	graphics_window gw;       /* declaration of gw as being of class
    				     graphics_window */

	gw.do_handle_events();

	delete gw;
}

    
Thanks in advance, any other helpful suggestions would also be appreciated.
    
    Marcus.

T.RTitleUserPersonal
Name
DateLines
754.1function protos?PCINT::MERRILLBrad Merrill DECtp SWEWed May 10 1989 12:1911
	At a guess, the "declaration" error message seems to imply that
it hasn't found a function prototype for the Xlib function in question.
I did a quick search of DECW$INCLUDE:*.H and there are "extern func()"
statement, but these may not be sufficient for c++.  I would suggest
providing explicit function prototypes for the Xlib routines that you
reference.


			/Brad

754.2Since some of us may be starting a new project...IO::MCCARTNEYJames T. McCartney III - DTN 381-2244 ZK02-2/N24Thu May 18 1989 03:105
    Would you mind sharing where and how you got a C++ compiler?
    
    James
    

754.360428::QUODLINGJust a Coupl&#039;a days....Thu May 18 1989 11:397
        
        re .2
        
        Isn't GNU (aka Free Software Foundation) releasing one.
        
        q

754.4C++ - where37404::boniniYou are only coming through in waves...Thu May 18 1989 11:5413
	Check the C++ notes conference (cadsys::c_plus_plus) for locations
and experiences.  Lots of info there.

	Quickly, there are two you can get.  cfront is a C++ preprocessor
distributed by AT&T.  Someone internally can get it for you but it costs
money since it's not ours.

	The GNU C++ (g++) is free, on the net, and a compiler instead of
a front-end.

	Again, info on both in the aforementioned notes conference.

754.5Who maintains the compiler?IO::MCCARTNEYJames T. McCartney III - DTN 381-2244 ZK02-2/N24Thu May 18 1989 18:266

But do you really want to build production software based on freeware?

James

754.6You're referring to X :-)STAR::BRANDENBERGSi vis pacem para bellumThu May 18 1989 18:272
    

754.7Supported is not necessarily better...7486::WITHROWRobert WithrowFri May 19 1989 15:066
Besides, the Gnu C compiler is known to be more reliable and in fact
``better'' in almost every way than the ``supported'' compiler.

Also, should you discover a compiler bug, I'll bet you can fix it yourself
much faster than to wait for a fix via the QAR method.

754.8Unsupported is never better though...IO::MCCARTNEYJames T. McCartney III - DTN 381-2244 ZK02-2/N24Sat May 20 1989 13:5825
    re: .-1 
    
    What happens  when  a  customer  using  you  code,  compiled  through a
    freeware compiler, finds a bug, induced by bad code in the compiler and 
    because of the damage it causes sues Digital. Are you prepared to say:
    
    ``I thought that someone else's compiler is better than anything we can
      build.''
    
    Exactly who did the tests of the Gnu compiler, where are the regression
    tests suites, and who has checked for conformance to Digital's quality 
    standards?
    
    I'm just not ready to ``bet my business'' nor my customer's on someone
    else's unsupported mistakes.
    
    And as to fixing the  compiler  if  it  has  a bug, that's not what I'm
    being paid for.  My manager would  not  like  it  if  I when to him and
    said, ``Sorry, we're slipping 3 weeks while we  figure out what's wrong
    with   our  unsupported  compiler.''  A  discussion  about  the  salary
    continuation plan would most certainly ensue.
    
    James
    

754.9NIH at work again30790::ROSESat May 20 1989 16:0526
    Re .8: The problems you mention hold for all software not developed by
    DEC, be it 'supported' or not. You are making a generic "not invented
    here" pitch to do everything in house. 
    
    The problems you mention are also possible with the MIPS C compiler, or
    with the parts of Ultrix we got from U. C. Berkeley and AT&T and Sun,
    or with all the other software we buy...
    
    What happens when a customer using your hardware, whose gate arrays
    were designed using Valid Logic Systems' GED schematics editor, finds a
    bug, induced by bad code in the schematics editor, and because of the
    damage it causes sues Digital. Are you prepared to say:
    
    "Valid Logic Systems is a leader in electronic CAD technology and for
    this reason we relied on their schematics editor rather than using our
    own (SUDS)?"
    
    [For those of you unfamiliar with hardware design: DEC has about 1000
    GED licenses from Valid. GED is to many DEC hardware engineers as LSE
    is to VMS software engineers. SUDS was an in-house predecessor to GED
    which ran on DECsystem-20s using VS-11 graphics terminals.]
    
    Your example shows a 3 week slip to fix a compiler bug. Does DEC
    respond to compiler SPR's with a fix in less than three weeks? Having
    the sources to fix bugs yourself can be a big advantage... 

754.10(standard disclaimer: I'm not a lawyer)56733::MESSENGERBob MessengerSat May 20 1989 18:2419
Re: .9

>    Re .8: The problems you mention hold for all software not developed by
>    DEC, be it 'supported' or not.

No, they don't.  There is a disclaimer on the GNU software that specifically
states that the software is unsupported, i.e. the Free Software Foundation
accepts no responsibility for its quality.

>    What happens when a customer using your hardware, whose gate arrays
>    were designed using Valid Logic Systems' GED schematics editor, finds a
>    bug, induced by bad code in the schematics editor, and because of the
>    damage it causes sues Digital.

We sue Valid Logic Systems.  We *couldn't* sue the Free Software Foundation
because GNU is unsupported.
    
				-- Bob

754.11PSW::WINALSKIPaul S. WinalskiSun May 21 1989 17:2422
RE: .10

If a customer finds a bug in shipped code, it doesn't matter whether it got
there due to bad logic at the source level or a compiler bug.  The fact that it
slipped out the door in a product release indicates inadequate testing of the
product before it was shipped.  The fault is entirely the development team's.
GNU C or other "freeware" is no different from a home-grown utility or software
tool that a development team writes to get their job done.  In both cases
(freeware and the home-grown tool), the development team has the sources and has
assumed the responsibility to fix problems in the tool, if they arise.

It's a trade-off:  if you use the DEC compiler, you don't have to fix problems
that you find, but the fix might not be as timely as you'd like.  If you use
the freeware compiler, the bug fixes can be as timely as you like, but you must
make them yourself.

--PSW

P.S.:  Discussions of scenarios involving lawsuits are not appropriate for NOTES
       conferences.  You wouldn't want your notes presented in court as evidence
       that DEC itself admits it is at fault in such circumstances, would you?

754.12If you want to stake *your* career on a lottery ticket...56733::MESSENGERBob MessengerSun May 21 1989 17:318
Re: .11

In that case (i.e. if it's the development team's fault if something goes
wrong) no project should use freeware unless they also budget the time
to test it and maintain it.  Otherwise they're taking a foolish gamble.

				-- Bob

754.13I use GCC under Ultrix.56564::thomasThe Code WarriorSun May 21 1989 17:5019
[This note was written from a program compiled by GCC]

GCC allows me to make asure my code works in a ANSI C environment and
GCC also catches many of the common mistakes that programmers make.  It
is simply another tool for maintaining/developing the software that I
work on.  I also use the MIPS C compiler, the standard Ultrix compiler,
and the VAX C compiler in my work.

The support of GCC is a non-issue.  I use GCC for development and
debugging but I use pcc/mcc to generate the production code.  Just
because I use freeware, does not mean that I am dependent on it.  I can
switch to another tool if I need to.  But I do agree that becoming
dependent on freeware with having someone officialy responsible to
support it is stupid.

It is my goal to make sure all my programs work correctly in a ANSI
C/POSIX 1003.1 environment.  The only tool that I can use to verify
this is GCC until the time comes along that Digital supplies me a ANSI C compiler.

754.14End of rathole (closeing statement)7486::WITHROWRobert WithrowMon May 22 1989 00:1938
re: <<< Note 754.8 by IO::MCCARTNEY "James T. McCartney III...

Since I was the one to start this rathole, I feel I should get to post
my rejoinder before terminating it:

>    What happens  when  a  customer  using  you  code,  compiled  through a
>    freeware compiler, finds a bug, induced by bad code in the compiler and 
>    because of the damage it causes sues Digital. Are you prepared to say:
>    
>    ``I thought that someone else's compiler is better than anything we can
>      build.''"
    
What happens  when  a  customer  using  you  code,  compiled  through the
VAX C compiler, finds a bug, induced by bad code in the compiler and 
because of the damage it causes sues Digital. Are you prepared to say:
    
    ``I thought that our compiler is better than anything else in the world.'' "

(These what-happens-when-you-get-sued retorts get so tiresome!)

I have SPRd bugs in the C compiler (both inside and outside of digital) and
have generally gotten "Thank you for your SPR.  This bug will be fixed in 
a future release."  I'm not carping at the compiler folks;  They have their
priorities and I have mine.  To them, my bug is likely just one more thing
that needs to be fixed; to me it likely the most importing thing.  Who pays
for the "extra three weeks" to work around the compiler bug?  What if I could
fix it myself in a couple of days?  Does your manager really care if the
three weeks is due to person A's bug or person B's bug?

The choice of compiler is just one more issue that requires "engineering
tradeoffs".  If using a non-Dec or freeware product frightens you then
dont use one.  But don't kid yourself that you have automatically eliminated
your cost and risk.

==========
And with this I formally declare this rathole not merely dead, but really
most sincerely dead!

754.158088::MERRILLBrad Merrill DECtp SWEThu May 25 1989 15:3810
There is an internal C++ compiler available, see the VAX C++ conference.
No, its probably not a good idea to do a product based on it "today", but
there is no reason that advanced development couldn't happen, with actual
product dates deffered until the supported version of C++ is released.
We used to call this paralell development.  It would probably help the
C++ project if they knew there were groups willing to do active development
with it.
				/Brad