TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Mike Bilow
from: Paul Rider
date: 1995-06-18 23:23:32
subject: Register Variables

Hello Mike,

 MB> Paul Rider wrote in a message to Mike Bilow:

 PR> boy it would be nice if somebody could tell a #pragma
 PR> directive  or something that kept a variable out of
---snip---

 MB> Declare the variable with the ANSI C standard "volatile" keyword.
Didn't work...

 MB> Post the actual class definition extract.  I assume 
 MB> that you have some global class instance with a private 
 MB> data member declared "volatile int" or something of 
You assumed correctly... There is a global cMOUSE instance. Many of my
other objects are built assuming it, and a few other exist. Well, here is
the definition as you asked...

class cMOUSE
{
   private:

   //Mouse stuff
   APIRET16       rc;
   HMOU           hmou;
   USHORT         fsEvents, fWait;
   MOUEVENTINFO   meibuf;
   NOPTRRECT mourt;
   MOUQUEINFO      QueDataRec; /* Ptr to 2-word structure */
   QWORD Time; //struc{ unsigned long ulLo; unsigned long ulHi; };
   BOOLEAN EventHappened; //Used ONLY to signal the WaitForMessage friend function!!!
   
   PTRLOC PtrPos;

   char Visible;
   volatile int  Buttons;
   char  Installed;
   int  NumPress;
   unsigned long LB_time;
   unsigned long CB_time;
   unsigned long RB_time;
   volatile int LB_x;
   volatile int LB_y;   //position of of mouse cursor at last release...
   volatile int CB_y;
   volatile int CB_x;
   volatile int RB_x;
   volatile int RB_y;

   public:
   friend void WaitForMessage(void);//blocks until keyboard, or mouse input...

   volatile int  x;
   volatile int  y;
   volatile int  x_at_last;
   volatile int  y_at_last;
   volatile char pressed_flag; // will be value of buttons if any pressed,
and keeps the x/y_at_last constant while this flag is non-zero

   unsigned long DblClickTime; //# of tocks between a set of the dclick flag.
    //by default DblClickTime is set to 40000
   
   cMOUSE();
   ~cMOUSE();
   void Init();
   BOOLEAN Show(void);
   void Hide(void);
   void Update( );
   void Move( int x_,int y_ );

   BOOLEAN LBP(void);
   BOOLEAN RBP(void);
   BOOLEAN LRBP(void);
   BOOLEAN cMOUSE::CBP(void);
   BOOLEAN cMOUSE::LCBP(void);
   BOOLEAN cMOUSE::RCBP(void);
   BOOLEAN cMOUSE::LCRBP(void);
   BOOLEAN cMOUSE::LB_DCLK(void);
   BOOLEAN cMOUSE::RB_DCLK(void);
   BOOLEAN cMOUSE::CB_DCLK(void);
   BOOLEAN IsVisible(void);
    //updates x/y_at_last with coords of last button press.
   void cMOUSE:: prev_pressLB(void);
   void cMOUSE::prev_releaseLB(void);//updates x/y with coords of last
button release.
   int cMOUSE::num_presses(void);

   int GetX(); //** THESE ARE THE SINGLE MOST ANNOYING NECCESSARY METHODS
   int GetY(); //** THANKS TO THE LACK OF FUNCTIONALITY (or my mis-use of)
               //** the volatile keyword

   int cMOUSE::LastPressX();//returns the X coordinate from last (any) button press!
   int cMOUSE::LastPressY();
unsigned int cMOUSE::but_state(void);//current status of button's
   void cMOUSE::appearance( char Char,char XorMask );
};

Ok, there is the class def'n... I haven't further messed with attaining
success with Borland's volatile keyword. As you see there are several
member variables clearly labeled 'volatile'. I would assume that from this
def'n the code that used these variables would not be optimized. However
further inspection (after much frustration of routines never being executed
because the lack of change in the mouse state) with the debugger tells me
that they have indeed been optimized. I've learned to live with it for now,
but I'd like to know of a way around it, since it's pretty messy to call
(for example) GetX() in a routine that's allready a busy one.
                                Paul Rider.

--- Maximus/2 2.02
* Origin: Rodent! Bbs ( Os/2 ) (1:163/427)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 163/427 335 307 99 12/12 3615/50 396/1 270/101 105/103 42 712/515
@PATH: 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.