What is this macro doing?

In portaudio, there are data type definitions like paInt32 and paFloat32.

I was looking at the header file where these are defined:
1
2
3
4
5
6
7
8
9
typedef unsigned long PaSampleFormat;  
#define paFloat32        ((PaSampleFormat) 0x00000001) 
#define paInt32          ((PaSampleFormat) 0x00000002) 
#define paInt24          ((PaSampleFormat) 0x00000004) 
#define paInt16          ((PaSampleFormat) 0x00000008) 
#define paInt8           ((PaSampleFormat) 0x00000010) 
#define paUInt8          ((PaSampleFormat) 0x00000020) 
#define paCustomFormat   ((PaSampleFormat) 0x00010000) 
#define paNonInterleaved ((PaSampleFormat) 0x80000000)  


It looks just like values being cast to unsigned int, but how would this approximate different datatypes?
They are not data types. They are integer constants that have one of the bits set.

1
2
3
4
5
6
7
8
#define paFloat32        ((PaSampleFormat) 0x00000001) // first bit set
#define paInt32          ((PaSampleFormat) 0x00000002) // second bit set
#define paInt24          ((PaSampleFormat) 0x00000004) // third bit set
#define paInt16          ((PaSampleFormat) 0x00000008) // fourth bit set
#define paInt8           ((PaSampleFormat) 0x00000010) // fifth bit set
#define paUInt8          ((PaSampleFormat) 0x00000020) // sixth bit set
#define paCustomFormat   ((PaSampleFormat) 0x00010000) // seventeenth bit set
#define paNonInterleaved ((PaSampleFormat) 0x80000000) // thirty-second bit set 


They are probably meant to be used with bit masks to allow multiple of them in the same value.

 
PaSampleFormat frmt = paInt24 | paNonInterleaved; // non-interleaved 24 bit integer format 


https://en.wikipedia.org/wiki/Mask_%28computing%29
Last edited on
Yes, not sure what I was thinking, you're right they are just flags that can be or'ed together passed as arguments.
Topic archived. No new replies allowed.