Thread: Follow up to 32/64 issue

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    63

    Follow up to 32/64 issue

    Posted here as this appears to be a Win64 issue only.
    follow up to this post:
    32/64 bit issue

    The code compiles and runs fine on gcc/g++ 4.8.2 on 64 bit Linux Mint 17 and OpenSuSE 13.1 Linux (g++ 4.8.1) 32 and 64 bit .

    James


  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Look closely at all the hard-coded (literal) values. It is likely some of those reflect an assumption about the size of some type.

    Also look closely at every point where sizeof() has been used. It is fairly obvious, even on a casual look, that the "update" to go from 32 to 64 bit converted some literal values representing (assumed) sizes of types to expressions in terms of sizeof(). If even one of those changes was careless (and looking at the organic nature of the code, I'd bet that is the case) it would explain your problem.

    Either of the above are particularly likely the culprit given that the code manipulates void pointers all over the place. It is also likely there are multiple such errors.

    Assumptions to look out for, as any may be wrong.
    1) An integral type is a particular size (2,4,....)
    2) A pointer type is a particular size (4,8, .....)
    3) Two different pointer types are the same size (admittedly, this assumption is likely to be true in practice)
    4) Some integral type and some pointer type are the same size.


    Another thing to look for (as Salem pointed out in the other thread) is that the code is doing bit fiddling with signed ints. Bit fiddling with signed integral types has undefined (at best, unspecified) results if any of the values being fiddled are negative.

    This isn't a win64 issue though. You're just getting lucky that the embedded assumptions happen to work on compilers where they work. Such is the case when in the realm of implementation-defined behaviour.
    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
    Mar 2013
    Posts
    63
    grumpy,
    As a well respected contributer to this site I want to thank you for examining the code and providing
    your direction insights. Unfortunatly the code is not mine and as a still novice,aging c/c++ coder just following it is a bit of a chore .


    In my research I did find many articles and forum discussions about the 64 bit implementation of Variable Argument Lists.


    My head scratching comes about by the apparent success of gcc/g++ on Linux64 and Tiny-C 64 on Windows.


    Thanks again,


    James

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Where does it crash?
    I highly recommend running the program in valgrind, it'll let you know if your program is writing/reading/allocation/freeing memory it shouldn't be; it even tells you about reading uninitialized memory.
    As Salem & grumpy point out, messing with signed variable bits is dangerous, but gcc with the -Wall flag should tell you where you're doing this, so it should be an easy fix. It's also best to always compile with -Werror when finalizing your program.

  5. #5
    Registered User
    Join Date
    Mar 2013
    Posts
    63
    Yarin,
    Last I knew valgrind was linux only.
    If you had read my last post a little more carefully you would notice there is NO problem on Linux.

    James

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by jcfuller View Post
    Last I knew valgrind was linux only.
    This had escaped me....

    Well, you could compile the program for Windows as usual, then run it through Wine, through valgrind.

    Or, you could try Dr. Memory. I haven't tried it, but it appears to fit the bill, and is available for Windows.

    EDIT: Sorry looks like Dr. Memory is 32-only. :l You could still try Wine/valgrind.
    Last edited by Yarin; 10-10-2014 at 10:12 AM.

  7. #7
    Registered User
    Join Date
    Mar 2013
    Posts
    63
    It's the recursion that is killing it with 64 bit MinGW gcc,VC++
    It's all handle with built in functions instead of macros.


    TinyC 64 copies all the registers to the stack and uses basically the same macros as 32bit


    The 64bit Linux gcc and the 64bit MinGW gcc handle it differently.
    MinGW gcc, I assume, follows the VC++ way and as is often the case it was butchered


    Some insight:
    https://blog.nelhage.com/2010/10/amd64-and-va_arg/





    James

  8. #8
    Registered User
    Join Date
    Mar 2013
    Posts
    63
    This turned out to be a DUH, and really a non va_list issue.


    The original basic source was doing a REDIM PRESERVE on an empty array so there was nothing to preserve.
    If the same code uses just REDIM or the arrays contain data all is well!
    Now I guess the question is why does it work on 32bit ?
    The algorithm or translator needs to be aware of an empty array and flag it as an error.
    Again, Thank you all for your time on this matter.


    James

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by jcfuller View Post
    This turned out to be a DUH, and really a non va_list issue.
    Forgive me if I don't seem surprised.

    Quote Originally Posted by jcfuller View Post
    The original basic source was doing a REDIM PRESERVE on an empty array so there was nothing to preserve.
    If the same code uses just REDIM or the arrays contain data all is well!
    Now I guess the question is why does it work on 32bit ?
    That's probably just a sign of using realloc() on an uninitialised pointer. It working with one target but not another is just par for the course with undefined behaviour.

    Quote Originally Posted by jcfuller View Post
    The algorithm or translator needs to be aware of an empty array and flag it as an error.
    Or handle the reallocation safely.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. which path to follow??
    By wakish in forum C++ Programming
    Replies: 7
    Last Post: 10-17-2005, 02:08 PM
  2. Is Sedgewick's a good book to follow?
    By anoopks in forum C Programming
    Replies: 3
    Last Post: 04-05-2004, 08:59 PM
  3. follow up to AVATARS thread
    By axon in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 09-30-2003, 04:58 AM
  4. follow up for anonytmouse
    By Thantos in forum Windows Programming
    Replies: 0
    Last Post: 09-17-2003, 09:08 PM
  5. follow up to if and then statements
    By mikezmr2 in forum C++ Programming
    Replies: 2
    Last Post: 09-20-2001, 05:35 PM