简体   繁体   English

“ #pragma import on”有什么作用?

[英]What does '#pragma import on' do?

I have a C header file starting with this: 我有一个以此开头的C头文件:

#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. 我很好奇#pragma import在做什么。 There's a #pragma import on ARM , and on AIX , but #pragma import on doesn't seem like it would work in either case. 在ARMAIX 有一个#pragma import ,但是在这两种情况下, #pragma import on似乎都不起作用。

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). 有趣的是,搜索“ pragma import on” -ada会发现一个非常相似的MIT样板头文件 (以及其他许多包含相似代码的文件),因此大概有一个指向(尽管我怀疑我拥有的文件是否重要) )。

So, is there some ancient compiler where #pragma import on does something? 那么,是否有一些古老的编译器在其中#pragma import on执行某些操作? 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. 此标头似乎表明该杂语已被Apple Computer,Inc.的MrC [pp]编译器使用 ,我不熟悉。

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. Wikipedia的Macintosh Programmer's Workshop链接到Archive.org,以获取有关此文档的一些文档,您可以从此处访问MrC / MrCpp相关文档 ,并获得指向MrC的实用说明的PDF链接。

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. import pragma表示将符号视为从另一个片段导入。 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. 他们应该在此标头中使用import pragma。 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. 请注意,这表示库导出应该在公共头文件中标记为import。 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”. import pragma永远不会应用于文件范围的符号,即使用关键字“ 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. 如果设置了导入编译指示,它将禁用其内部状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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