I am trying to get the cpusubtype of the device where my app is running . Is there any chance to only get the cpusubtype? Referring to this: Detect processor ArmV7 vs ArmV7s. Objective-C
sysctlbyname("hw.cpusubtype", &value, &length, NULL, 0);
Will it return numbers like 9,11,12,64 ? If yes can I then just use
if hw.cpusubtype(64){
//code for arm64
}
The code from the thread Detect processor ArmV7 vs ArmV7s. Objective-C that you linked to
int32_t value = 0;
size_t length = sizeof(value);
sysctlbyname("hw.cpusubtype", &value, &length, NULL, 0);
puts the CPU subtype into the value
variable, so you would compare that with the
subtypes defined in <mach/machine.h>
, for example:
if (value == CPU_SUBTYPE_ARM_V7) {
// ...
}
But if your intention is to check if your app is running on a 32-bit or a 64-bit processor then you have to get the "cputype", and not "cpusubtype", as demonstrated here https://stackoverflow.com/a/20105134/1187415:
sysctlbyname("hw.cputype", &value, &length, NULL, 0);
if (value == CPU_TYPE_ARM64) {
// ARM 64-bit CPU
} else if (value == CPU_TYPE_ARM) {
// ARM 32-bit CPU
} else {
// Something else.
}