home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Programmieren / Kurztests / DiceC / doc / EXTENSIONS.DOC < prev    next >
Text File  |  1994-02-01  |  15KB  |  389 lines

  1.  
  2. extensions/extensions                    extensions/extensions
  3. extensions/EXTENSIONS                    extensions/EXTENSIONS
  4.  
  5.                    COMPILER EXTENSIONS
  6.  
  7.                  AUTO LIBRARY OPENNING
  8.  
  9.     Certain Amiga libraries are supported on an autoinit basis.  Normally
  10.     you declare the library base variable then OpenLibrary() it in your
  11.     main.
  12.  
  13.     If you EXTERN the library base variable instead then it will be brought
  14.     in from auto.lib along with autoinit code to automatically
  15.     OpenLibrary() it on startup and CloseLibrary() it on shutdown.
  16.  
  17.     DICE uses this feature to automatically open floating point libraries,
  18.     dos.library, etc...  The following libraries may currently be openned
  19.     in this fashion (note that if you attempt to use the feature on a
  20.     library that does not support auto-open a link error will occur):
  21.  
  22.     asl.library            (2.0)
  23.     dos.library
  24.     fifo.library
  25.     gadtools.library        (2.0)
  26.     graphics.library
  27.     mathffp.library
  28.     mathtrans.library
  29.     mathieeesingbas.library     (2.0, works w/ 1.3)
  30.     mathieeesingtrans.library   (2.0, works w/ 1.3)
  31.     mathieeedoubbas.library
  32.     mathieeedoubtrans.library
  33.     intuition.library
  34.     layers.library
  35.     utility.library         (2.0)
  36.  
  37.     Others will be added in the future, eventually all the libraries.
  38.  
  39.     Note that the auto-open features is fully upward compatible to earlier
  40.     methods of declaring the base pointer and openning the libraries
  41.     manually.  Declaring a library base variable causes the associated
  42.     autolib routines to NOT be linked into the executable.
  43.  
  44.            TYPE QUALIFIER AND STORAGER QUALIFIER EXTENSIONS
  45.  
  46.     availability:   reg-only = registered users
  47.  
  48.  
  49.     extension    avail        comment
  50.  
  51.     volatile    all        force auto's to NOT be placed in registers
  52.     const    all        place data items in the code section (see -ms/-mS)
  53.     __autoinit    all        cause a subroutine to be run automatically
  54.                 before _main (for variables, puts variable in
  55.                 alternate section)
  56.     __autoexit    all        cause a subroutine to be run automatically
  57.                 before _exit
  58.     __interrupt all        NOT AMIGA COMPATIBLE
  59.     __chip    reg-only    cause storage to be placed in CHIP memory
  60.     __far    all        cause storage to be referenced using absolute-long
  61.     __near    all        cause storage to be referenced using A4-relative
  62.     __aligned    all        cause storage to be aligned on a longword boundry
  63.     __unaligned all        allows structures to be byte-aligned (at your own risk)
  64.     __geta4    reg-only    cause a subroutine to setup the A4 data base
  65.                 pointer
  66.  
  67.     __shared    all        storage is placed in the code section and thus
  68.                 is shared between instances of a resident'd
  69.                 program.  EXPERIMENTAL
  70.  
  71.     __regargs    all        specify function takes registered arguments
  72.                 even if -mr/-mR/-mRR is not used.
  73.  
  74.     __stkargs    all        specify function takes normal stack based
  75.                 args despite the possibility that -mr/-mR/-mRR
  76.                 has been specified.
  77.  
  78.     __dynamic    reg-only    dynamic linking of routines/variables at run-
  79.                 time
  80.  
  81.     __noprof    all        disable profiling for a procedure
  82.  
  83.     volatile
  84.     This storage qualifier normally specifies that the physical storage
  85.     is 'synched' at the end of each line of C code.  DICE already does
  86.     this by virtue of not doing any major optimizations.  Under ANSI
  87.     this storage qualifier also forces auto variables to NOT be placed
  88.     in a register.    This can be important if you use <setjmp.h>
  89.     (see MAN/SETJMP.DOC for more information)
  90.  
  91.     const
  92.     The const type qualifier can be handled in different ways by DICE.
  93.     As of the 2.05.11 version of DC1, any const qualified object is
  94.     placed in the code section.  Before 2.05.11 const qualified
  95.     objects were only placed in the code section if -ms or -mS was
  96.     also given to DCC.
  97.  
  98.     Normally a const qualified item is handled as a near item (pc-rel)
  99.     within the module that declares it, and handled with absolute-long
  100.     references in modules that extern it.
  101.  
  102.     If -ms is used then string constants are made const.  If -mS is
  103.     used then all external references to const items use pc-relative
  104.     instead of the absolute-long addressing mode.  Do NOT use -mS
  105.     unless your final code size is less than 32KBytes.
  106.  
  107.     Using -ms can substantially reduce the number of run-time
  108.     relocations for -r residentable programs as well as the run-time
  109.     dynamically allocated data+bss space.
  110.  
  111.     (refer to DCC.DOC, -ms and -mS options for details)
  112.  
  113.     __autoinit
  114.     __autoexit
  115.  
  116.     These storage qualifiers cause a routine to be called after libraries
  117.     are openned before _main is called (__autoinit), and just before
  118.     libraries are closed after _exit is called (__autoexit).  They may
  119.     be used for low level initialization and shutdown and may not make
  120.     any c.lib calls (i.e. malloc, fopen, open, etc... may not be called)
  121.  
  122.     __autoinit void
  123.     fubar()
  124.     {
  125.         NewList(&MyList);
  126.     }
  127.  
  128.     __autoinit may be used with a variable declaration.  The variable
  129.     is placed in an alternate section.  This is mainly of use for
  130.     ROMable applications to group declared data together, with a base
  131.     section pointer in the ROM startup object and a 'terminator'
  132.     in the last object module.  For example, a 'ROM MODULE LIST' may
  133.     be constructed painlessly using this feature.
  134.  
  135.     __autoinit int a;        /*    altbss,bss    */
  136.     __autoinit int a = 4;        /*    altdata,data    */
  137.     __autoinit const int a;     /*    altcode,code    */
  138.     __autoinit const int a = 4; /*    altcode,code    */
  139.  
  140.     SUGGESTION:  use dcc -a to oberve the assembly generated.  Note
  141.     that BSS data verses INITIALIZED data go into different sections.
  142.  
  143.     __interrupt
  144.  
  145.     This storage qualifier for a subroutine causes all used registers to
  146.     be saved and restored, including the scratch registers, and returns
  147.     via RTE instead of RTS.
  148.  
  149.     THIS KEYWORD IS NOT AMIGA COMPATIBLE
  150.  
  151.     __noprof
  152.  
  153.     When a source module is compiled with -prof each routine is
  154.     generally profiled.  The __noprof qualifier for a procedure
  155.     declaration disables profiling for the routine in question.
  156.     This is used, specifically, to prevent the profiling routine
  157.     from profiling itself (result = crash) in the support library.
  158.  
  159.     __chip
  160.  
  161.     This storage qualifier forces a static or global data item to be
  162.     placed in CHIP memory.    Normally this precludes being able to make
  163.     such programs resident (-r option), but if you also use the 'const'
  164.     type qualifier you can make such programs resident....    The 'const'
  165.     type qualifier assumes that the contents of the object will NEVER
  166.     be modified!!!
  167.  
  168.     __chip short ImageData[] = { ... };        read-write object
  169.                             program not residentable
  170.  
  171.     __chip const short ImageData[] = { ... };   read-only object
  172.                             program is residentable
  173.  
  174.     __far
  175.  
  176.     __far int a;
  177.  
  178.     This storage qualifier determines how a data object is to be
  179.     referenced.  It overides the data model for the reference and
  180.     forces the ABSOLUTE-LONG addressing mode to be used.
  181.  
  182.     Note that __chip data is automatically forced to be __far.
  183.     When compiling -mD the default is to use __far references.
  184.  
  185.     WARNING:  Using __far addressing on non-const data items precludes
  186.     the executable from being residentable.
  187.  
  188.     __near
  189.  
  190.     __near int a;
  191.  
  192.     This storage qualifier forces a small-data model (A4-Relative)
  193.     reference to a data object.  When using the -md (default) data
  194.     model data objects are accessed as near items by default.
  195.  
  196.     __aligned
  197.  
  198.     This storage qualifier forces the static, global, or auto data
  199.     object to be aligned on a longword boundry.
  200.  
  201.     foo()
  202.     {
  203.         __aligned struct FileInfoBlock fib;
  204.         ...
  205.     }
  206.  
  207.     WARNING:    __aligned does not work if this subroutine or any
  208.     higher level subroutine is passed a *structure* where said
  209.     structure is not aligned.  We are talking about passing actual
  210.     structures here, not pointers to structures (which work fine
  211.     with __aligned).  Note that passing char or short integers works
  212.     just fine with __aligned.
  213.  
  214.     __unaligned
  215.  
  216.     This storage qualifier allows structures to be byte-aligned in
  217.     terms of NOT padding them to the nearest word or longword.
  218.  
  219.         __unaligned struct foo {
  220.         char a;
  221.         } a, b, c;
  222.  
  223.     In the above example, sizeof(a), sizeof(b), and sizeof(c) is 1.
  224.  
  225.     USE AT YOUR OWN RISK.  Accessing word/long/ptr items at odd
  226.     byte addresses is illegal for the 68000 and will generate an
  227.     exception.  This qualifier is useful mainly for character
  228.     structures that must map over a text file.
  229.  
  230.     __geta4
  231.  
  232.     This storage qualifier on a subroutine definition forces the
  233.     subroutine to save A4 and then load A4 with the small-data model
  234.     data pointer on subroutine entry, then restore the original
  235.     contents of A4 on subroutine exit.  This is useful for
  236.     inter-context calls when using the small-data model.
  237.  
  238.     __geta4 void
  239.     fubar()
  240.     {
  241.  
  242.     }
  243.  
  244.     Unfortunately, using this qualifier precludes being able to
  245.     generate a residentable executable since a residentable
  246.     executable's data space pointer is unknown at link time.
  247.  
  248.     __shared
  249.  
  250.     This storage modifier places the global or static variable
  251.     declaration into the code segment, thus this variable will be
  252.     SHARED across multiple running instances of the same program,
  253.     assuming the program has been made RESIDENT.  A program that has
  254.     not been made resident will not share variables.
  255.  
  256.     __config    (UNDER TESTING, DO NOT USE FOR ANY REAL PROJECT)
  257.  
  258.     This storage modifier generates loading and saving code for all
  259.     variables in question.    You should not declare any pointers as
  260.     a saved pointer value will not be valid when the program is run
  261.     later on.
  262.  
  263.     If no configuration file exists the initialized value of the static
  264.     or global storage is used, for example:
  265.  
  266.         __config int a = 34;
  267.  
  268.     'a' will be 34 if no configuration file exists.  If a configuration
  269.     file does exist all __config variables will be overriden with the
  270.     values stored in the configuration file.
  271.  
  272.     The name and version of the configuration file must be specified
  273.     by the programmer as two initialized global variables or a link
  274.     error will occur.  For example:
  275.  
  276.         char *ConfigFile = "s:myprog.config";
  277.         long ConfigVersion = 1;
  278.  
  279.     DICE configuration code will automatically ignore any configuration
  280.     file whos version does not equal ConfigVersion.  As a programmer,
  281.     you must change ConfigVersion if you modify ANY __config
  282.     declaration, the ordering of any __config declaration, or the
  283.     ordering of any object modules in your link.  If you fail to do so,
  284.     the program may attempt to load an invalid configuration.
  285.  
  286.     The configuration is automatically loaded on program startup,
  287.     before _main() (__main from assembly) gets run, and if ConfigFile
  288.     is non-NULL on program exit (_exit) then the configuration will be
  289.     saved.     Thus, __config is supported even if you use the _main()
  290.     entry point and _exit() exit point.
  291.  
  292.     WARNING: ONLY PROCESSES MAY USE THE __CONFIG TYPE QUALIFIER.  If
  293.     you plan to run a program as a task instead of a process then you
  294.     cannot use __config.  Note that any WORKBENCH or CLI run program
  295.     is a process.  DOS handlers are also processes, but it is not
  296.     suggested that __config be used for any program that is to be
  297.     a DOS handler (i.e. a DOS device).  Libraries and exec Devices are
  298.     NOT processes... not even tasks usually, and thus __config may not
  299.     be used for such programs.
  300.  
  301.     __regargs
  302.     __stkargs
  303.  
  304.     Normally these qualifiers are used in conjuction with the -mr,
  305.     -mR, or -mRR flags.  Even so, they are usually used only to
  306.     force a normal C calling convention for callback functions (when
  307.     you supply intuition, graphics, exec, or whomever with a callback
  308.     function the OS will call you with arguments on the stack).
  309.  
  310.     Specifying neither causes the routine to default to either stack
  311.     args or register args depending on the DCC flags.  Specifying
  312.     __stkargs forces the function to use stack based arguments no
  313.     matter what options are used.  Specifying __regargs forces the
  314.     function to use register based arguments in the same manner.
  315.     Specifying both forces the function to generate two entry points
  316.     (same thing occurs by default when -mr is used).
  317.  
  318.     Please refer to the discussion in REGARGS.DOC for more information
  319.  
  320.     __dynamic
  321.  
  322.     The __dynamic storage qualifier is used to declare routines that
  323.     do not exist at link or load time but will be loaded run-time.
  324.     The overall effect is to generate autoinit code to dynamically
  325.     load an indirect pointer to the declared variable/procedure and
  326.     autoexit code to release your references on said pointer.
  327.  
  328.     DICE transparently declares the variables/procedures as pointers
  329.     and transparently indirects whenever they are used in code.  The
  330.     __dynamic feature is INCREDIBLY POWERFUL, allowing a program to
  331.     interface to third-party object modules at run-time.  Generally,
  332.     this type of interface is more desirable than a shared-library
  333.     when the module in question are huge -- do major things, as well
  334.     as allowing third-party replacement of modules without effecting
  335.     program operation or requiring a relinking of the program.
  336.  
  337.     Please refer to DYNAMIC.DOC for a more involved explanation.
  338.  
  339.  
  340.     --------------------------------------------------------------------
  341.  
  342.                DYNAMIC STACKS (-gs option)
  343.  
  344.     DICE now has a new option, -gs, which generates stack checking code for
  345.     every subroutine.  But, unlike SAS/C or MANX, DICE is able to allocate
  346.     new stack chunks when the current stack runs out.  Essentially this
  347.     means that you can compile and run programs which expect a lot of stack
  348.     without having to remember to give a larger STACK command in your
  349.     CLI.  Since DICE allocates and deallocates stack chunks according to
  350.     program usage, an efficient use of the amiga's memory is made.
  351.  
  352.     There are two global variables associated with this option.  You, the
  353.     programmer, may override either or both of them by declaring them
  354.     yourself.  The variables are:
  355.  
  356.     long _stack_fudge = 4096;
  357.     long _stack_chunk = 32768;
  358.  
  359.     The defaults are shown above.  You can modify these variables either
  360.     by declaring them globally or changing them on the fly (usually from
  361.     main()).
  362.  
  363.     _stack_fudge specifies the minimum amount of stack before DICE creates
  364.     a new stack.  This should be AT LEAST 2048 BYTES!  This parameter MUST
  365.     be able to handle the worst case stack usage for any given subroutine.
  366.  
  367.     The second parameter specifies the chunk size for any new stacks
  368.     created.  A new stack is created whenever the current available
  369.     stack goes below _stack_fudge, but only applies to the next level
  370.     of subroutine... the current subroutine (that detected the low stack
  371.     condition) must be able to run in the old stack.  Stacks are freed
  372.     as they become unused.
  373.  
  374.     If for any reason DICE is unable to allocate a new stack, it will
  375.     call the stack_abort() routine.  If you do not define such a routine,
  376.     the one from the library will be used (which abort()s the program).
  377.  
  378.     If you DO define a stack_abort() routine, then you must take one
  379.     of two actions:
  380.  
  381.     (1) abort() or exit() the program
  382.  
  383.     (2) return (causes DICE to retry allocating the stack)
  384.  
  385.     If DICE is unable to reallocate the stack after (2), it will call
  386.     stack_abort() again.
  387.  
  388.  
  389.