简体   繁体   中英

What does '#pragma import on' do?

I have a C header file starting with this:

#if PRAGMA_ONCE
#pragma once
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if PRAGMA_IMPORT
#pragma import on
#endif

#if PRAGMA_STRUCT_ALIGN
    #pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
    #pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
    #pragma pack(2)

I'm curious what #pragma import is doing. There's a #pragma import on ARM , and on AIX , but #pragma import on doesn't seem like it would work in either case.

Interestingly, searching for "pragma import on" -ada finds an extremely similar MIT boilerplate header file (along with a bunch of other files containing similar code), so presumably there's a point to this (although I doubt it matters in the file I have).

So, is there some ancient compiler where #pragma import on does something? I doubt there's any practical point to knowing this, but I'm curious.

This header seems to indicate that the pragma is used by something called MrC[pp] compiler from Apple Computer, Inc. , which I'm not familar with.

Wikipedia's Macintosh Programmer's Workshop links to Archive.org for some documentation on that, and you can reach MrC/MrCpp Related Documentation from there, with a link to a PDF for MrC's pragmas.

And here's the definition for that specific pragma:

Syntax

#pragma import on
#pragma import off
#pragma import reset
#pragma import [list] <name_list>

Semantics

The import pragma indicates that a symbol is to be treated as though it were imported from another fragment. This affects code generation for references to both variables and functions. Imported variables are addressed indirectly. Imported functions are called using cross fragment “glue”. This includes calls within the same source file (and thus includes recursive calls).

Developers of shared libraries are expected to use the same header file for both external clients and their own internal builds. They should use the import pragma in this header. Clients obviously need to treat these symbols as imports and internal builds need to treat them as imports if they are to be updatable/patchable. Note that this says the library exports should be tagged import in the public header. This is consistent with the client's view.

  1. The import pragma is never applied to file scoped symbols, ie, those using the keyword “static”. Specifying such a symbol in the list form will be reported as an error by the pragma.

  2. The import and export pragmas are orthogonal and may be applied independently.

  3. The import and internal pragmas are mutually exclusive. The import pragma will disable the internal status if it is set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM