Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Union LARGE_INTEGER

This code is from MSDN. So, we have an union, which contains the struct and the variable. In my code I declared the prototype of union and then initialized the "QuadPart" of union. But printing the Quad Part doesn’t give the full number but the LowPart of it. Is it a way it should be?

typedef union _LARGE_INTEGER
{
        struct {
                unsigned LowPart;
                unsigned HighPart;
        } u;
        unsigned long long QuadPart;
} LARGE_INTEGER;


int main(int argc, char** argv){
        LARGE_INTEGER num1;
        num1.QuadPart = 0x1020304050607080;
        printf("Low: %x, high: %x, quad: %x\n", num1.u.LowPart, num1.u.HighPart, num1.QuadPart);


        return 0;
}

I expected the full number displayed by num1.QuadPart

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

use llx for printing long long type printing in hex format

#include <stdio.h>

typedef union _LARGE_INTEGER
{
        struct {
                unsigned LowPart;
                unsigned HighPart;
        } u;
        unsigned long long QuadPart;
} LARGE_INTEGER;


int main(int argc, char** argv){
        LARGE_INTEGER num1;
        num1.QuadPart = 0x1020304050607080;
        printf("Low: %x, high: %x, quad: %llx\n", num1.u.LowPart, num1.u.HighPart, num1.QuadPart);


        return 0;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading