利用union做类型转换

Categories: Program
Tags: No Tags
Comments: No Comments
Published on: 2009/09/10
#include 
 
using namespace std;
 
union conv {double arg; struct fl{float real; float imag;}f;};
 
int main()
{
    float farr[] = {1.0, 2.0};
    double* pd = (double*)(farr);
    conv c;
    c.arg = *pd;
    cout << c.f.real << endl;
    cout << c.f.imag << endl;
    return 0;
}
No Comments - Leave a comment

Leave a comment

Your email address will not be published. Required fields are marked *


Welcome , today is Thursday, 2018/02/22