how to use datatypes: word and dword in c

Posted on 2014-08-21
Last Modified: 2014-08-21

which include library do I need to have word and dword.
Question by:rgb192
    LVL 84

    Expert Comment

    typedef theTypeYouWantToUseForWord word;
    typedef theTypeYouWantToUseForDword dword;
    LVL 82

    Expert Comment

    by:Dave Baldwin
    Neither one.  'word' and 'dword' are part of the language.
    LVL 84

    Expert Comment

    You might find some appropriate types to use in
    LVL 31

    Expert Comment

    Did you mean DWORD and WORD rather than dword and word?
    In any case, none of these four tokens are part of the ANSI C language. DWORD and WORD are created by Microsoft so that if you use them, you will have more trouble porting to other systems, and be stuck using Microsoft. Do avoid them if you do not need them.

    A 32-bit unsigned integer. The range is 0 through 4294967295 decimal.

    This type is declared in IntSafe.h as follows:

    typedef unsigned long DWORD;
    A 16-bit unsigned integer. The range is 0 through 65535 decimal.

    This type is declared in WinDef.h as follows:

    typedef unsigned short WORD;
    The size of long is implementation dependent. Maybe Microsoft constrains long to be 32-bits.
    LVL 16

    Accepted Solution

    It's totally compiler dependent.  

    Data types like BYTE, WORD, DWORD are NOT a part of the C/C++ language standard.  They also are not a part of the standard C/C++ library standard.

    It's totally possible that your compiler doesn't have any .h file that defines these data types.  After all, my Microsoft Visual Studio C/C++ compiler defines them in <minwindef.h>, a file your compiler likely does not have.

    So you can either do a search of the .h files that came with your compiler, or you can do some trial and error with the sizeof() operator on your compiler and create your own typedefs to define these data types.

    BTW, my current C++ compiler defines these datatypes like this:
    typedef unsigned long DWORD
    typedef unsigned short WORD
    typedef unsigned char BYTE

    These typedefs might or might now work for you as they assume that a long is 32-bit, and short is 16-bit.

    Author Closing Comment

    I type
    no intellisense until I add
    <minwindef.h> to the top of file


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now