Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!uunet!infonode!usenet From: doyle@doyled.b23b.ingr (Doyle C. Davidson) Newsgroups: comp.windows.x.motif Subject: Re: writing Widgets with Float resources Message-ID: <1991May31.135212.6584@infonode.ingr.com> Date: 31 May 91 13:52:12 GMT References: <13743@dog.ee.lbl.gov> Sender: usenet@infonode.ingr.com (Usenet Administrator) Reply-To: doyle@doyled.b23b.ingr.com Organization: Intergraph Corporation - Third Party Software Lines: 42 > >I have started to write a few Motif widgets (subclassing Primitive, >for instance), and have things working fine as long as various >resources are "ints" (XmRInt type resources). But I need them >to be "floats" (XmRFloat types). To paraphrase "X Window System Toolit" by Asente and Swick (this is a great book!): A problem exists with storing FLOAT value into an argument list; the C compiler will cast the FLOAT value to an integer due to the definition of XtArgVal. The most reliable way to do this is to declare a union type: union { float f; int i; } hack; Assign the FLOAT value to hack.f and store hack.i into the argument list. If the resource is defined as a pointer to a FLOAT value, this problem does not occur. This only works if sizeof(float) == sizeof(int). IMHO: The proper way to do PORTABLE float/double resources is to implement them as pointer to values. You will have to copy the value into a private field since the resource field itself will be a pointer. I have done this before but I backed away and used ints for my resource value since float was overkill since screen resolution is integer based. > Mark Anderson Doyle ------------------------------------------------------------------- Doyle C. Davidson | Intergraph Corp. | Intergraph - Everywhere you look!! Third Party Software | 1 Madison Industrial Park | Huntsville, AL 35806 | These comments are... (205) 730-2000 | | X-clusively my own. ..!uunet!ingr!doyle | - or - doyle@ingr.com | -------------------------------------------------------------------