c - 在 C 中将 Int32 类型转换为 sCplx16 IQ 样本

标签 c structure int casting

我有以下问题

我有一个结构

typedef struct
{

    Int16 real;
    Int16 imag;

}sCplx16;

Int32 Data; //Data has real-imag packed into 32 bits. real-imag are 16 bits each.

现在我将 Int32 Value 与 real-imag 打包在一起。我已经编写了接受 sCplx16 参数的函数,但我不想将其设置为 Int32,因为函数内部会有大量更改。

为了避免这种情况,我对变量进行了类型转换

Fun( (sCplx16)Data);


fun.c

Fun(sCplx16 DataPtr)

{  

   //

}


Inside the function, I find that value received are mapped correctly to
DataPtr.real and DataPtr.imag.

Is this typecasting correct? Someone told me that it will vary with compiler.
meaning imaginary will be first 16 bits and real will be next 16 bits.

我认为只有字节顺序会影响这一点,而不是编译器

请分享您的意见

谢谢

最佳答案

我不确定编译器如何处理带有值传递的函数的类型转换。 但如果你改变函数来传递int32的指针,那么据我所知它只会受到字节顺序的影响。

关于c - 在 C 中将 Int32 类型转换为 sCplx16 IQ 样本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4212340/

相关文章:

c - 局部变量的返回值。哪一个是不好的做法?

c - 退出应用程序时 luaF_newproto 处的 Lua 5.1 段错误

c# - 在 WinForm 中声明一个全局整数

c - 如何将整数转换为char数组并反转以获得相同的数字?

c - 删除链表中的重复元素

c - 为什么 isdigit 总是返回 false?

structure - Qooxdoo大型应用结构

common-lisp - 常见的 lisp : slot-value for defstruct structures

c - 从 C 中的结构构建字符串

java - 如何获取整数输入的最后一个数字