Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "Gestalt" do?

Tags:

c

unix

macos

On Mac OS X, what does the function gestalt do? 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?

like image 641
fdh Avatar asked Jul 11 '26 00:07

fdh


1 Answers

Gestalt gives you details about the system the application is running on, such as the OS version. Here is a simple example to get the Mac OSX version on the system this binary is run:

#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/

This should give a response like: Mac Version: 10.6.8

I created this example after reading the official docs.

like image 51
JRideout Avatar answered Jul 13 '26 16:07

JRideout