简体   繁体   English

“格式塔”有什么作用?

[英]What does “Gestalt” do?

On Mac OS X, what does the function gestalt do? 在Mac OS X上,格式塔的功能是什么? What is it used for? 这有什么用途? Could you please give a brief example? 你能举个简单的例子吗? I know that it has something to do with system calls, but what exactly? 我知道它与系统调用有关,但具体到底是什么?

Gestalt gives you details about the system the application is running on, such as the OS version. Gestalt为您提供有关运行应用程序的系统的详细信息,例如操作系统版本。 Here is a simple example to get the Mac OSX version on the system this binary is run: 下面是一个简单的示例,可以在运行此二进制文件的系统上获取Mac OSX版本:

#include <stdio.h>
#include <Gestalt.h>

int main() {
    SInt32 versMaj, versMin, versBugFix;
    Gestalt(gestaltSystemVersionMajor, &versMaj);
    Gestalt(gestaltSystemVersionMinor, &versMin);
    Gestalt(gestaltSystemVersionBugFix, &versBugFix);

    printf("Mac Version: %d.%d.%d\n", versMaj, versMin, versBugFix);
}

compile and run this test with: 编译并运行此测试:

gcc -framework Carbon test.c && ./a.out

You may aslo need a flag like -I/Developer/Headers/FlatCarbon/ 您可能还需要一个像-I/Developer/Headers/FlatCarbon/的标志

This should give a response like: Mac Version: 10.6.8 这应该给出如下响应: Mac Version: 10.6.8

I created this example after reading the official docs . 我在阅读官方文档后创建了这个例子。

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

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