Next: MSP430 Variable Attributes, Previous: MeP Variable Attributes, Up: Variable Attributes [Contents][Index]

#### 6.32.8 Microsoft Windows Variable Attributes

You can use these attributes on Microsoft Windows targets. x86 Variable Attributes for additional Windows compatibility attributes available on all x86 targets.

`dllimport`
`dllexport`

  The `dllimport` and `dllexport` attributes are described in Microsoft Windows Function Attributes.

`selectany`

  The `selectany` attribute causes an initialized global variable to have link-once semantics. When multiple definitions of the variable are encountered by the linker, the first is selected and the remainder are discarded. Following usage by the Microsoft compiler, the linker is told not to warn about size or content differences of the multiple definitions.

  Although the primary usage of this attribute is for POD types, the attribute can also be applied to global C++ objects that are initialized by a constructor. In this case, the static initialization and destruction code for the object is emitted in each translation defining the object, but the calls to the constructor and destructor are protected by a link-once guard variable.

  The `selectany` attribute is only available on Microsoft Windows targets. You can use `__declspec (selectany)` as a synonym for `__attribute__ ((selectany))` for compatibility with other compilers.

`shared`

  On Microsoft Windows, in addition to putting variable definitions in a named section, the section can also be shared among all running copies of an executable or DLL. For example, this small program defines shared data by putting it in a named section `shared` and marking the section shareable:

      int foo __attribute__((section ("shared"), shared)) = 0;

      int
      main()
      {
        /* Read and write foo.  All running
           copies see the same value.  */
        return 0;
      }

  You may only use the `shared` attribute along with `section` attribute with a fully-initialized global definition because of the way linkers work. See `section` attribute for more information.

  The `shared` attribute is only available on Microsoft Windows.

Next: MSP430 Variable Attributes, Previous: MeP Variable Attributes, Up: Variable Attributes [Contents][Index]