Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ XtOffset(3) — OSF1 1.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

XtGetResources(1)

XtOffsetOf(1)

 

Name

XtOffset — determine the byte offset of a field within a structure pointer type. 

Synopsis

Cardinal XtOffset(pointer_type, field_name)

    Type pointer_type;
    Field field_name;

Arguments

pointer_type
Specifies a type that is declared as a pointer to the structure.

field_nameSpecifies the name of the field for which to calculate the byte offset. 

Description

XtOffset computes the relative address of a field in bytes, given a pointer to a structure.  Using XtOffset, a program can use field names, instead of numeric byte offsets, to specify addresses in a structure relative to a base pointer.  XtOffset can be used at compile time in static initializations. 

XtOffset is often used to determine the location of an instance variable in a widget record.  Resource fields are defined in terms of offsets from a base address from the beginning of a widget.  Thus, a resource value can be kept up to date by the Resource Manager without any knowledge of the instance structure of the widget;  it uses just a relative byte offset. 

XtOffset is less portable than XtOffsetOf. 

The following code uses XtOffset to define the foreground resource in the Athena Label widget:

static XtResource resources[] = {
{
XtNforeground,/∗ Resource name is foreground ∗/
XtCForeground,/∗ Resource class is Foreground ∗/
XtRPixel,/∗ Resource type is Pixel ∗/
sizeof(Pixel),/∗ allocate enough space to hold a Pixel value ∗/
XtOffset(LabelWidget, label.foreground),/∗where in instnce strct∗/
XtRString,/∗Default val is a String (will need conversion)∗/
XtDefaultForeground/∗ Default address ∗/
},
           .
           .
}

XtOffset is a macro defined in <X11/Intrinsic.h> as follows:

#define XtOffset(type,field)  ((unsigned int) (((char ∗) \
     (&(((type)NULL)->field)))--((char ∗) NULL)))

See Also

XtGetResources(1), XtOffsetOf(1). 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026