[swift-users] C unsigned int[] imported as tuple?
Thierry Passeron
thierry.passeron at gmail.com
Sat Oct 29 05:34:34 CDT 2016
Hi everyone,
I’m working on a project where I deal with mach here and there, and strangely enough this C struct (from mach/processor_info.h)...
struct processor_cpu_load_info { /* number of ticks while running... */
unsigned int cpu_ticks[CPU_STATE_MAX]; /* ... in the given mode */
};
is imported in Swift 3 (at least in Xcode8.1 beta) as…
public struct processor_cpu_load_info {
public var cpu_ticks: (UInt32, UInt32, UInt32, UInt32) /* number of ticks while running... */ /* ... in the given mode */
...
}
I find it strange because the index of each UInt32 value depends on machine.h define(d) indexes for CPU_STATE_USER, CPU_STATE_SYSTEM etc…
So the only way to access them in the tuple « format » is to hard code cpu_ticks.0 or cpu_ticks.1 etc… and thus we loose the defined named indexes from machine.h
Am I missing something? What do you guys think of this matter?
For me this tuple should have been at least imported with named fields or even better as [UInt32] array...
Best regards,
Thierry
More information about the swift-users
mailing list