CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Size of address on a machine is size of integer. True or false?

  1. #1

    Size of address on a machine is size of integer. True or false?

    Size of address on a machine is size of integer. True or false?

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Size of address on a machine is size of integer. True or false?

    false

  3. #3
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Size of address on a machine is size of integer. True or false?

    Maybe, depends on the machine and the compiler.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Size of address on a machine is size of integer. True or false?

    Quote Originally Posted by forumuser11@gmail.com View Post
    Size of address on a machine is size of integer. True or false?
    Absolutely false. Look at 16-bit MSDOS and the various C++ compilers that run on that system.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Size of address on a machine is size of integer. True or false?

    I once worked on an embedded 68000 system. The addresses were 32bit and so were the integers, so, not always false.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  6. #6
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,164

    Re: Size of address on a machine is size of integer. True or false?

    Here is a helpful link that shows the number of bits for various integral types, along with the number of bits for a pointer on a 64-bit machine.

    http://en.wikipedia.org/wiki/64-bit#...ge_data_models

    The point is, that regardless of whether it is a 16-bit, 32-bit or 64-bit machine, you should not assume in your code that a pointer has the same number of bits as an integral type, sometimes it's true, sometimes its not. If you do make the assumption, then at the very least your code will not be portable.

  7. #7
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Size of address on a machine is size of integer. True or false?

    false.

    On modern machines ints are 4 bytes and addresses are 8. Only on old 32-bit machines are they the same size.

  8. #8
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Size of address on a machine is size of integer. True or false?

    Quote Originally Posted by ninja9578 View Post
    Only on old 32-bit machines are they the same size.
    Only if you believe that all C++ coding is done for PC's. There are an awful lot of (current) 32bit processors used in embedded applications out there. Think ARM for example.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  9. #9
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Size of address on a machine is size of integer. True or false?

    I'm aware of that, but judging by the question, I would assume that the OP is learning C++, and almost all learning is done on a PC. I've done plenty of embedded myself, and have had all sorts of weird sizes for words and addresses. I usually find with embedded is that ints are 32-bit and addresses are 16.

  10. #10
    Join Date
    Aug 2007
    Posts
    858

    Re: Size of address on a machine is size of integer. True or false?

    sizeof(size_t) should always equal sizeof(void*). Otherwise the standard doesn't guarantee anything other than sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long).

  11. #11
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Size of address on a machine is size of integer. True or false?

    Quote Originally Posted by forumuser11@gmail.com View Post
    Size of address on a machine is size of integer. True or false?
    Remember "define is"?
    Sometimes? Always? What's your question?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  12. #12
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,768

    Re: Size of address on a machine is size of integer. True or false?

    Quote Originally Posted by Speedo
    Otherwise the standard doesn't guarantee anything other than sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long).
    It also guarantees that sizeof(char) == 1, CHAR_BIT >= 8, and the various minimum ranges for the standard built-in integer types.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)