KCC - Kayte C Compiler
1.10.0
A C compiler implementation with preprocessor, lexer, parser, and code generator
Loading...
Searching...
No Matches
macros
apple_platform.h
1
/*
2
* apple_platform.h - A header for detecting macOS (Apple Silicon) and iOS.
3
*
4
* This file uses pre-defined macros provided by Apple's Clang compiler
5
* to identify the target platform at compile time. This is useful for
6
* writing C code that needs to run on multiple Apple devices.
7
*/
8
9
// =============================================================================
10
// 1. Header Guard
11
// =============================================================================
12
#ifndef APPLE_PLATFORM_H
13
#define APPLE_PLATFORM_H
14
15
// =============================================================================
16
// 2. Include Apple's Target Conditionals
17
// =============================================================================
18
// This is the official Apple header that defines the TARGET_OS_* macros.
19
// It's the standard way to check for the target operating system.
20
#ifdef __APPLE__
21
#include <TargetConditionals.h>
22
#endif
23
24
// =============================================================================
25
// 3. Platform & Architecture Detection Macros
26
// =============================================================================
27
// We define our own set of clean, easy-to-use macros based on the official ones.
28
29
// Check for macOS
30
#if defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1
31
#define PLATFORM_MACOS 1
32
#endif
33
34
// Check for iOS or iOS Simulator
35
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1
36
#define PLATFORM_IOS 1
37
#endif
38
39
// Check for Apple Silicon (ARM64 architecture)
40
#if defined(__arm64__)
41
#define PLATFORM_ARCH_ARM64 1
42
#endif
43
44
// A specific macro for macOS running on Apple Silicon
45
#if PLATFORM_MACOS && PLATFORM_ARCH_ARM64
46
#define PLATFORM_MACOS_SILICON 1
47
#endif
48
49
// =============================================================================
50
// 4. API Visibility and Calling Conventions
51
// =============================================================================
52
// When building frameworks or libraries, it's good practice to control which
53
// functions are exported. This is a common pattern in platform headers.
54
55
#ifdef __cplusplus
56
// Use C-style linkage for C++ projects to prevent name mangling.
57
#define EXTERN_C extern "C"
58
#else
59
#define EXTERN_C extern
60
#endif
61
62
// Defines a function as being part of the public API of a library.
63
#define PUBLIC_API EXTERN_C __attribute__((visibility("default")))
64
65
// =============================================================================
66
// 5. Example of Platform-Specific Function Prototypes
67
// =============================================================================
68
// Here is how you might declare functions that have different implementations
69
// depending on the platform.
70
71
PUBLIC_API
void
initialize_platform_services();
72
73
#if PLATFORM_MACOS
74
// This function would only be declared and available when compiling for macOS.
75
PUBLIC_API
const
char
* get_mac_serial_number_string();
76
#endif
77
78
#if PLATFORM_IOS
79
// This function would only be available when compiling for iOS.
80
PUBLIC_API
const
char
* get_ios_device_model_name();
81
#endif
82
83
84
#endif
// End of header guard APPLE_PLATFORM_H
Generated by
1.14.0