Thread: Why are my pointers/references 32bit and not 64bit?

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    11

    Why are my pointers/references 32bit and not 64bit?

    I'm running Windows 7, 64-bit, on a 64-bit machine of course.

    I'm tried using both Code::Blocks + the Borland 5.5 free compiler, and also CodeLite + GNU g++ compiler.

    This is the code I have written to run the test:

    Code:
    	const short BITS_PER_BYTE = 8;
    	const short BYTES_PER_ADDRESS = sizeof( void* );
    	const short MEMORY_SLOT_SIZE = (BYTES_PER_ADDRESS * BITS_PER_BYTE);
    	cout << "Size: " << MEMORY_SLOT_SIZE << "bit" << endl;

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Running under 64-bit windows on 64-bit hardware is not all there is to it. 32-bit programs, including 32-bit compilers, can mostly run on a 64-bit system. If your compiler is 32-bit, it will produce 32-bit executables, regardless of whether it is executed on a 64-bit system.

    The Borland 5.5 free compiler is 32-bit.

    GNU compilers (gcc - for GNU compiler collection) can be built for 32-bit or 64-bit targets, although support for 64-bit targets is a little patchy. If you have obtained executables built for a 32-bit target, it will produce 32-bit code. The two most commonly used windows versions of gcc are Cygwin and mingw, and both are only released in a 32-bit version (IIRC a 64-bit version of mingw is under development, currently about beta status, but I haven't checked for a while). The CodeLite IDE is currently distributed with a mingw 32-bit compiler (or no compiler).


    You could have worked all this out by reading the respective documentation (for Borland 5.5, mingw, or even for the CodeLite IDE).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    11
    Quote Originally Posted by grumpy View Post
    Running under 64-bit windows on 64-bit hardware is not all there is to it. 32-bit programs, including 32-bit compilers, can mostly run on a 64-bit system. If your compiler is 32-bit, it will produce 32-bit executables, regardless of whether it is executed on a 64-bit system.

    The Borland 5.5 free compiler is 32-bit.

    GNU compilers (gcc - for GNU compiler collection) can be built for 32-bit or 64-bit targets, although support for 64-bit targets is a little patchy. If you have obtained executables built for a 32-bit target, it will produce 32-bit code. The two most commonly used windows versions of gcc are Cygwin and mingw, and both are only released in a 32-bit version (IIRC a 64-bit version of mingw is under development, currently about beta status, but I haven't checked for a while). The CodeLite IDE is currently distributed with a mingw 32-bit compiler (or no compiler).


    You could have worked all this out by reading the respective documentation (for Borland 5.5, mingw, or even for the CodeLite IDE).
    Thanks for your help.

    Regarding the last bit of advice, I'm sure you're right. However, it would probably have taken a lot longer. For one, I didn't even know where to start looking (I didn't realise the compiler was the cause, although I thought it may have been).

    Thanks again.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Vic Webster Jnr View Post
    Regarding the last bit of advice, I'm sure you're right. However, it would probably have taken a lot longer.
    If you are going to assume your time is more valuable than that of other members here, you will find few people willing to help. Yes, people here are volunteers, but volunteers are a special breed - act as if their time is less valuable than your own, or is something you can tap into when you're too lazy to work for yourself, and they become less willing to help.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I would also point out that references don't really have a size.
    I.e. if you have char &x; then sizeof(x) is sizeof(char), and using &x anywhere gives you a pointer so it's sizeof(char*).

    Edit: Okay so you can put one inside a struct and then check the struct size.
    Last edited by iMalc; 11-06-2012 at 12:30 PM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    IIRC a 64-bit version of mingw is under development, currently about beta status, but I haven't checked for a while
    If you are talking about what I think you are talking about, the project hasn't made much progress, and I highly doubt it ever will.

    Other sources though have a very capable "MinGW64" distribution of GCC 4.5 and above.

    Soma

  7. #7
    Registered User
    Join Date
    Oct 2012
    Posts
    11
    Quote Originally Posted by grumpy View Post
    If you are going to assume your time is more valuable than that of other members here, you will find few people willing to help. Yes, people here are volunteers, but volunteers are a special breed - act as if their time is less valuable than your own, or is something you can tap into when you're too lazy to work for yourself, and they become less willing to help.
    Well ... sometimes it comes down to "three minutes of your time will save three days of my time". Literally! I've put weeks worth of work - over five hours every day - into learning C++, and that's obviously just a start. I've asked only a handful of questions on these forums. I try and solve the problems myself, but with my limited experience and knowledge that's sometimes a big ask.

    Besides that - and with all due respect - I reckon there would be not many questions asked in this forum - or any forum - that are not covered by "documentation somewhere".

    I believe I've been quite gracious with those that have been willing to help, including yourself. Thanks for your help and for the detailed response I noticed that you made to my other thread too. It is very much appreciated, believe me!
    Last edited by Vic Webster Jnr; 11-06-2012 at 04:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making programs work on 64bit and 32bit machines?
    By inu11byte in forum C Programming
    Replies: 5
    Last Post: 08-07-2012, 12:21 AM
  2. Pointers and references?!? Help!
    By alyeska in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2008, 10:23 AM
  3. Pointers v References
    By m37h0d in forum C++ Programming
    Replies: 28
    Last Post: 06-30-2008, 01:29 PM
  4. 32bit - 64bit portability
    By l2u in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2007, 05:13 PM
  5. prog runs on 64bit - seg faults on 32bit
    By hollie in forum C Programming
    Replies: 13
    Last Post: 12-08-2006, 01:59 AM