Int24

I'm doing some dsp stuff and I have this __int24 struct.
However, I'm getting this error

cannot convert from const int24_t to int32_t. How can I fix this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Most architectures do not include a 24 bit integer
#ifndef INT24
#define INT24
#pragma pack(push, 1) // This will align all of the data nicely

// Most architectures do not support a 24 bit integer
// so a way to convert 24 bit integer data had to be
// defined. This structure is used for both its
// pointers as well as its native integer conversions. 
struct __int24 {

	Byte bytes[3];

#if LITTLE_ENDIAN

	__int24& operator = (const __int32& integer) {
		bytes[0] = (integer & 0x000000ff);
		bytes[1] = (integer & 0x0000ff00) >> 8;
		bytes[2] = (integer & 0x00ff0000) >> 16;
		return *this;
	}

	operator __int32 () {
		__int32 integer = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16);
		if (integer & 0x800000) 
			integer |= ~0xffffff;
		return integer;
	}

#else
#error endianness not supported
#endif // Endianness
};

#pragma pack(pop) // Restore old alignment
#endif // INT24 


1
2
3
4
5
6
7
void* int24_to_int32(int32_t *dest, const int24_t *source, size_t size) {

	for (size_t i = 0; i < size; i++)
		dest[i] = (int32_t)source[i]; // Operator defined in DataTypes.h

	return dest;
}
cannot convert from const int24_t to int32_t.
You cannot apply non-const operations to the const variable and conversion operator is not marked as const.

Try this: operator __int32 () const {
Topic archived. No new replies allowed.