views:

72

answers:

1

In an class header I have seen something like this:

enum {
    kAudioSessionProperty_PreferredHardwareSampleRate           = 'hwsr',   // Float64
    kAudioSessionProperty_PreferredHardwareIOBufferDuration     = 'iobd'   // Float32
};

Now I wonder what data type such an kAudioSessionProperty_PreferredHardwareSampleRate actually is?

I mean this looks like plain old C, but in Objective-C I would write @"hwsr" if I wanted to make it a string.

I want to pass such an "constant" or "enum thing" as argument to an method.

+3  A: 

This converts to an UInt32 enum value using the ASCII value of each of the entries. This style have been around for a long time in Mac OS headers.

'hwsr' has the same value as if you had written 0x68777372, but is a lot more reader friendly. If you used the @"hwsr" style instead you would need more than 4 bytes to represent the same.

The advantage of using this style is that you are actually able to quickly identify the content of a raw data stream if you can see the ASCII values of it.

Claus Broch
slightly incorrect: according to the C standard, values of enumeration constants and character constants both are `int` and not `UInt32` (see C99 6.7.2.2 §2 and 6.4.4.4 §10)
Christoph