Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ User's Guide - watcom c/c++ supports the use of some special keywords to describe system http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Watcom C/C++ supports the use of some special keywords to describe system
dependent attributes of functions and other object names.  These attributes
are inspired by the Intel processor architecture and the plethora of
function calling conventions in use by compilers for this architecture.  In
keeping with the ANSI/ISO C and C++ language standards, Watcom C/C++ uses
the double underscore (i.e., "__") or single underscore followed by
uppercase letter (e.g., "_S") prefix with these keywords.  To support
compatibility with other C/C++ compilers, alternate forms of these keywords
are also supported through predefined macros.

__near
    Watcom C/C++ supports the __near keyword to describe functions and other
    object names that are in near memory and pointers to near objects.

    Watcom C/C++ predefines the macros near and _near to be equivalent to
    the __near keyword.

__far
    Watcom C/C++ supports the __far keyword to describe functions and other
    object names that are in far memory and pointers to far objects.

    Watcom C/C++ predefines the macros far,  _far and SOMDLINK (16-bit only)
    to be equivalent to the __far keyword.

__huge
    Watcom C/C++ supports the __huge keyword to describe functions and other
    object names that are in huge memory and pointers to huge objects.  The
    32-bit compilers treat these as equivalent to far objects.

    Watcom C/C++ predefines the macros huge and _huge to be equivalent to
    the __huge keyword.

__based
    Watcom C/C++ supports the __based keyword to describe pointers to
    objects that appear in other segments or the objects themselves.  See
    the section entitled Based Pointers for an explanation of the __based
    keyword.

    Watcom C/C++ predefines the macro _based to be equivalent to the __based
    keyword.

__segment
    Watcom C/C++ supports the __segment keyword which is used when
    describing objects of type segment.  See the section entitled
    Based Pointers for an explanation of the __segment keyword.

    Watcom C/C++ predefines the macro _segment to be equivalent to the
    __segment keyword.

__segname
    Watcom C/C++ supports the __segname keyword which is used when
    describing segname constant based pointers or objects.  See the section
    entitled Based Pointers for an explanation of the __segname keyword.

    Watcom C/C++ predefines the macro _segname to be equivalent to the
    __segname keyword.

__self
    Watcom C/C++ supports the __self keyword which is used when describing
    self based pointers.  See the section entitled Based Pointers for an
    explanation of the __self keyword.

    Watcom C/C++ predefines the macro _self to be equivalent to the __self
    keyword.

_Packed
    Watcom C/C++ supports the _Packed keyword which is used when describing
    a structure.  If specified before the struct keyword, the compiler will
    force the structure to be packed (no alignment, no gaps) regardless of
    the setting of the command-line option or the #pragma controlling the
    alignment of members.

__cdecl
    Watcom C/C++ supports the __cdecl keyword to describe C functions that
    are called using a special convention.

    Notes:

     1. All symbols are preceded by an underscore character.

     2. Arguments are pushed on the stack from right to left.  That is, the
        last argument is pushed first.  The calling routine will remove the
        arguments from the stack.

     3. Floating-point values are returned in the same way as structures.
         When a structure is returned, the called routine allocates space
        for the return value and returns a pointer to the return value in
        register EAX

     4. For the 16-bit compiler, registers AX, BX, CX and DX, and segment
        register ES are not saved and restored when a call is made.

     5. For the 32-bit compiler, registers EAX, ECX and EDX are not saved
        and restored when a call is made.

    Watcom C/C++ predefines the macros cdecl,  _cdecl,  _Cdecl and SOMLINK
    (16-bit only) to be equivalent to the __cdecl keyword.

__pascal
    Watcom C/C++ supports the __pascal keyword to describe Pascal functions
    that are called using a special convention described by a pragma in the
    "stddef.h" header file.

    Watcom C/C++ predefines the macros pascal,  _pascal and _Pascal to be
    equivalent to the __pascal keyword.

__fortran
    Watcom C/C++ supports the __fortran keyword to describe functions that
    are called from FORTRAN.  It converts the name to uppercase letters and
    suppresses the "_" which is appended to the function name for certain
    calling conventions.

    Watcom C/C++ predefines the macros fortran and _fortran to be equivalent
    to the __fortran keyword.

__interrupt
    Watcom C/C++ supports the __interrupt keyword to describe a function
    that is an interrupt handler.

    Example:

         #include <i86.h>

         void __interrupt int10( union INTPACK r )
         {
                 .
                 .
                 .
         }

    The code generator will emit instructions to save all registers.  The
    registers are saved on the stack in a specific order so that they may be
    referenced using the "INTPACK" union as shown in the DOS example above.
    The code generator will emit instructions to establish addressability
    to the program's data segment since the DS segment register contents are
    unpredictable.  The function will return using an "IRET" (16-bit) or
    "IRETD" (32-bit) (interrupt return) instruction.

    Watcom C/C++ predefines the macros interrupt and _interrupt to be
    equivalent to the __interrupt keyword.

__declspec( modifier )
    Watcom C/C++ supports the __declspec keyword for compatibility with
    Microsoft C++.  The __declspec keyword is used to modify storage-class
    attributes of functions and/or data.  There are several modifiers that
    can be specified with the __declspec keyword:  thread,  naked,
     dllimport,  dllexport,  __pragma( "string" ),  __cdecl,  __pascal,
     __fortran,  __stdcall, and __syscall.  These attributes are a property
    only of the declaration of the object or function to which they are
    applied.  Unlike the __near and __far keywords, which actually affect
    the type of object or function (in this case, 2- and 4-byte addresses),
    these storage-class attributes do not redefine the type attributes of
    the object itself.  The __pragma modifier is supported by Watcom C++
    only.  The thread attribute affects data and objects only.  The naked,
     __pragma,  __cdecl,  __pascal,  __fortran,  __stdcall, and __syscall
    attributes affect functions only.  The dllimport and dllexport
    attributes affect functions, data, and objects.  For more information on
    the __declspec keyword, please see the section entitled
    The __declspec Keyword.

__export
    Watcom C/C++ supports the __export keyword to describe functions and
    other object names that are to be exported from a Microsoft Windows or
    OS/2 Dynamic Link Library (DLL).  See also the description of the "zu"
    option.

    Example:

         void __export _Setcolor( int color )
         {
                 .
                 .
                 .
         }

    Watcom C/C++ predefines the macro _export to be equivalent to the
    __export keyword.

__loadds
    Watcom C/C++ supports the __loadds keyword to describe functions that
    require specific loading of the DS register to establish addressability
    to the function's data segment.  This keyword is useful in describing a
    function that will be placed in a Microsoft Windows or OS/2 1.x Dynamic
    Link Library (DLL).  See also the description of the "nd" and "zu"
    options.

    Example:

         void __export __loadds _Setcolor( int color )
         {
                 .
                 .
                 .
         }

    If the function in an OS/2 1.x Dynamic Link Library requires access to
    private data, the data segment register must be loaded with an
    appropriate value since it will contain the DS value of the calling
    application upon entry to the function.

    Watcom C/C++ predefines the macro _loadds to be equivalent to the
    __loadds keyword.

__saveregs
    Watcom C/C++ recognizes the __saveregs keyword which is an attribute
    used by C/C++ compilers to describe a function that must save and
    restore all registers.

    Watcom C/C++ predefines the macro _saveregs to be equivalent to the
    __saveregs keyword.

__stdcall
    (32-bit only) The __stdcall keyword may be used with function
    definitions, and indicates that the 32-bit Win32 calling convention is
    to be used.

    Notes:

     1. All symbols are preceded by an underscore character.

     2. All C symbols (extern "C" symbols in C++) are suffixed by "@nnn"
        where "nnn" is the sum of the argument sizes (each size is rounded
        up to a multiple of 4 bytes so that char and short are size 4).
         When the argument list contains "...", the "@nnn" suffix is
        omitted.

     3. Arguments are pushed on the stack from right to left.  That is, the
        last argument is pushed first.  The called routine will remove the
        arguments from the stack.

     4. When a structure is returned, the caller allocates space on the
        stack.  The address of the allocated space will be pushed on the
        stack immediately before the call instruction.  Upon returning from
        the call, register EAX will contain address of the space allocated
        for the return value.  Floating-point values are returned in 80x87
        register ST(0).

     5. Registers EAX, ECX and EDX are not saved and restored when a call is

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson