home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gccdist / gcc / include / gnu_hacks.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-20  |  3.5 KB  |  82 lines

  1. /* <gnu_hacks.h>
  2.  *
  3.  * This header file contains hacks that will simulate the effects of certain
  4.  * parts of VAX-C that are not implemented in GNU-C.  This header file is
  5.  * written in such a way that there are macros for both GNU-C and VAX-C.
  6.  * Thus if you use the macros defined here in your program, you should be
  7.  * able to compile your program with either compiler with no source
  8.  * modifications.
  9.  *
  10.  * Note:  The globalvalue implementation is a little bit different than it
  11.  * is on VAX-C.  You can declare a data variable to be a globalvalue, but
  12.  * the data type that the compiler will see will be a pointer to that data
  13.  * type, not that data type.  If you find the warning messages intollerable,
  14.  * you can define a macro to type cast the globalvalue variable back to the
  15.  * expected type.  Since it is impossible to define a macro while expanding
  16.  * another macro, this was not done here.
  17.  *
  18.  * Also, globaldef/ref/value of enum is not implemented.  To simulate this
  19.  * in GNU-C, you can globaldef an integer variable, and then define all of
  20.  * the values that this variable can take to be globalvalue.
  21.  *
  22.  * The arguments to these macros are "fragile" (in the LaTeX sense).  This
  23.  * means that you cannot use type casts or expressions in the name field.
  24.  */
  25. #ifndef _GNU_HACKS_H
  26. #define _GNU_HACKS_H
  27. #define __GNU_HACKS_H_
  28.  
  29. /* internal macros for traditional vs ANSI */
  30. #ifdef __STDC__
  31. #define __GNU_HACKS_string(foo) #foo
  32. #define __GNU_HACKS_const const
  33. #else    /* => -traditional, or VAXC (just "stringizing", not 'const') */
  34. #define __GNU_HACKS_string(foo) "foo"
  35. #define __GNU_HACKS_const
  36. #endif
  37.  
  38. #ifdef __GNUC__
  39.  
  40. /* Store the data in a psect by the same name as the variable name */
  41. #define GLOBALREF(TYPE,NAME) \
  42.  TYPE NAME __asm("_$$PsectAttributes_GLOBALSYMBOL$$" __GNU_HACKS_string(NAME))
  43. #define GLOBALDEF(TYPE,NAME,VALUE) \
  44.  TYPE NAME __asm("_$$PsectAttributes_GLOBALSYMBOL$$" __GNU_HACKS_string(NAME)) = VALUE
  45.  
  46. #define GLOBALVALUEREF(TYPE,NAME) \
  47.  __GNU_HACKS_const TYPE NAME[1] __asm("_$$PsectAttributes_GLOBALVALUE$$" __GNU_HACKS_string(NAME))
  48. #define GLOBALVALUEDEF(TYPE,NAME,VALUE) \
  49.  __GNU_HACKS_const TYPE NAME[1] __asm("_$$PsectAttributes_GLOBALVALUE$$" __GNU_HACKS_string(NAME)) = {VALUE}
  50.  
  51. /* Store the data in a psect by a different name than the variable name */
  52. #define GBLREF_ALIAS(TYPE,NAME,ALIAS) \
  53.  TYPE NAME __asm("_$$PsectAttributes_GLOBALSYMBOL$$" __GNU_HACKS_string(ALIAS))
  54. #define GBLDEF_ALIAS(TYPE,NAME,ALIAS,VALUE) \
  55.  TYPE NAME __asm("_$$PsectAttributes_GLOBALSYMBOL$$" __GNU_HACKS_string(ALIAS)) = VALUE
  56.  
  57. /* Other non-standard qualifiers */
  58. #define _NOSHARE(NAME) NAME __asm("_$$PsectAttributes_NOSHR$$" __GNU_HACKS_string(NAME))
  59. #define _READONLY(NAME) NAME __asm("_$$PsectAttributes_NOWRT$$" __GNU_HACKS_string(NAME))
  60.     /* as of gcc 2.0, this does not work, so do not use it... */
  61. #define _ALIGN(NAME,BASE) NAME __attributes((aligned(1<<(BASE))))
  62.  
  63. #else    /* assume VAXC */
  64. /* These are the equivalent definitions that will work in VAX-C */
  65.  
  66. #define GLOBALREF(TYPE,NAME) globalref TYPE NAME
  67. #define GLOBALDEF(TYPE,NAME,VALUE) globaldef TYPE NAME = VALUE
  68.  
  69. #define GLOBALVALUEREF(TYPE,NAME) globalvalue TYPE NAME
  70. #define GLOBALVALUEDEF(TYPE,NAME,VALUE) globalvalue TYPE NAME = VALUE
  71.  
  72. #define GBLREF_ALIAS(TYPE,NAME,ALIAS) globalref{__GNU_HACKS_string(ALIAS)} TYPE NAME
  73. #define GBLDEF_ALIAS(TYPE,NAME,ALIAS,VALUE) globaldef{__GNU_HACKS_string(ALIAS)} TYPE NAME = VALUE
  74.  
  75. #define _NOSHARE(NAME) noshare NAME
  76. #define _READONLY(NAME) readonly NAME
  77. #define _ALIGN(NAME,BASE) _align(BASE) NAME
  78.  
  79. #endif    /*__GNUC__*/
  80.  
  81. #endif    /*_GNU_HACKS_H*/
  82.