突出显示为关键字的宏:pascal
在查看 FunkyOverlayWindow 的示例代码时,我刚刚发现了一个非常有趣的声明:
pascal OSStatus MyHotKeyHandler(
EventHandlerCallRef nextHandler,
EventRef theEvent,
void *userData
);
这里,pascal
被突出显示为关键字(标准 Xcode 配色方案中为粉红色)。但我刚刚发现它是一个宏,有趣的是在文件 CarbonCore/ConditionalMacros.h 中定义为:
#define pascal
那么,它应该做什么(或曾经是)?也许它在过去有什么特殊用途?
虽然这个讨论可能不太适合这里,但如果这与答案相关的话,了解为什么苹果仍然使用 Carbon 会很有趣。我没有使用 Carbon 的经验,但这段代码似乎设置了一个键盘事件处理程序,这让我想知道是否比 Cocoa 方法有任何优势。碳不会被完全去除吗?
While looking in the sample code for FunkyOverlayWindow, I just found a pretty interesting declaration:
pascal OSStatus MyHotKeyHandler(
EventHandlerCallRef nextHandler,
EventRef theEvent,
void *userData
);
Here, pascal
is highlighted as a keyword (pink in standard Xcode color scheme). But I just found it's a macro, interestingly enough defined in file CarbonCore/ConditionalMacros.h as:
#define pascal
So, what is (or was) it supposed to do? Maybe it had some special use in the past?
While this discussion might not be well suited here, it would be interesting to know why Apple still using Carbon if this relates to the answer. I have no experience in Carbon, but this code appears to set a keyboard event handler which makes me wonder if there are any advantages over the Cocoa approach. Won't Carbon be ever removed completely?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 68k Classic Mac OS 运行时下(例如,在 PowerPC或 x86 之前),C 和 Pascal 使用不同的调用约定,因此 C 应用程序在使用 Pascal 约定调用库时必须声明适当的约定(包括大多数操作系统)。该宏在同时代的编译器(例如 MPW、Metrowerks、Think C)中实现。
在所有较新的运行时和所有现代编译器中,不再识别该关键字,因此
ConditionalMacros.h
标头将其定义掉。该文件中有一些注释可能有助于解释更多内容 - 如果您感兴趣,请通读它。Under the 68k Classic Mac OS runtime (e.g, before PowerPC or x86), C and Pascal used different calling conventions, so C applications had to declare the appropriate convention when calling into libraries using the Pascal conventions (including most of the operating system). The macro was implemented in contemporaneous compilers (e.g, MPW, Metrowerks, Think C).
In all newer runtimes, and in all modern compilers, the keyword is no longer recognized, so the
ConditionalMacros.h
header defines it away. There are a few comments in that file which may help explain a bit more -- read through it, if you're game.您遇到了调用约定。
x86 的 pascal 调用约定在此处进行了描述。
非常有趣的是,它被定义为“无”,您会注意到这意味着它不再被使用。这在过去的 x86 领域很常见,尤其是在 Microsoft Windows API 中,因为处理器能够在调用结束时使用其特殊的
RET n
从堆栈中删除参数操作说明。具有 pascal 调用约定的函数有时是有利的,因为调用者在每次调用返回后不会显式调整堆栈指针。如果有人更了解为什么该宏仍然存在于代码库中,但已经被定义了,并且能给你一个更好的答案,我会很乐意撤回这个答案。
You have encountered a calling convention.
The pascal calling convention for the x86 is described here.
It is very interesting that it was defined-away-to-nothing, which you notice means that it is not used anymore. It was common in the old days in x86-land, especially in the Microsoft Windows APIs, because of the ability of the processor to remove parameters from the stack at the end of a call with its special
RET n
instruction. Functions with the pascal calling convention were sometimes advantageous, because the caller wasn't explicity adjusting the stack pointer after each call returned.If someone with more knowledge of why the macro still exists in the codebase, but is defined away comes along and gives you a better answer, I will happily withdraw this one.