Apps that work with XCode 3.1, crash with 3.2

Discussion in 'Mac Programming' started by Appleness, Nov 5, 2009.

  1. macrumors member

    Joined:
    Feb 26, 2009
    #1
    I use to write command line apps for number crunching.

    Recently I updated to SL and XCode 3.2, and I found that when I recovered and recompiled the projects I was developing, they seemed to build OK, but when I try to run them, they crash. They worked fine in Leopard and compiled with XCode 3.1.

    I get messages like "Abort trap", and "Segmentation Fault".

    I am not very keen on all the compiler options, so I do not know what to do.

    Thanks for your help
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    If you can post the debugger where they crash that would help.

    3.2 by default links against the 10.6 SDK which may do things a little differently (I just noticed this yesterday with a project I opened for the first time that crashed on SL but not on Leopard).
     
  3. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #3
    It might be a 64 bit versus 32 bit issue if you are building in Xcode 3.2.

    What does the debugger say?
     
  4. thread starter macrumors member

    Joined:
    Feb 26, 2009
    #4
    The debugger says:

    GDB: Program received signal: "EXC_BAD_ACCESS"
     
  5. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #5
    That isn't very helpful without any code. Find out which line of code causes the bad access.
     
  6. thread starter macrumors member

    Joined:
    Feb 26, 2009
    #6
    The line where it crash is that with the printf:

    struct parametros *Lee_parametros( sorteo puntero, char *nombre_fichero )
    {
    FILE *fichero;
    size_t tamano;
    struct parametros *un_parametro;
    int m;

    tamano = sizeof(struct parametros);
    un_parametro = (struct parametros *) malloc(tamano);
    printf("[0][0]=%i\n",(*puntero)[0][0]);
    .
    .
    .


    where sorteo is declared in the header file as:

    typedef int (*sorteo)[][10];
     
  7. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #7
    You can simplify your code a bit by doing this:

    Code:
    struct parametros *un_parametro = malloc(sizeof(struct parametros));
    What are you actually attempting to do with that printf statement? That typedef does not make much sense to me. What are you trying to declare something that is basically function pointer syntax to be treated as an int?

    Perhaps I am just misunderstanding your code here.
     
  8. thread starter macrumors member

    Joined:
    Feb 26, 2009
    #8
    You are right with your simplifying statement.
    "sorteo" is a pointer to a bidimensional array of int. I declared it with typedef to save typing in all the files where I use this kind of array.
    The printf statement is useless (I just wrote it for debugging purposes).

    I realize that the code is not perfect, but the question is why it crashes now, when it worked fine with Leopard and 3.1
     
  9. macrumors 603

    Joined:
    Aug 9, 2009
    #9
    Did you ever compile and run the code as 64-bit under Leopard? If not, then you might be incompatible with 64-bit. The problem could be with the default compilation architectures on Snow Leopard, which includes 64-bit. Turn off 64-bit on Snow Leopard and see what happens.
     
  10. thread starter macrumors member

    Joined:
    Feb 26, 2009
    #10
    Thankyou very much you all. That´s it. I turned off 64-bit, and now everything seems to work again.

    And now, how can I make my code 64-bit compatible? I guess I will have to change a lot of things. Just give me a clue about where I should begin to look for.

    Probably, my programs (heavy number crunching) would be much more efficient if compiled for 64-bit code. (?)

    Thanks again (I love Mac Rumors)
     
  11. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #11
    Have a look around at the Apple developers website, they have quite a few articles about making your code work on 64 bit.

    Always a good one is casting a pointer to an int and back (it's a stupid but common thing to do, works fine on 32 bit, crashes immediately on 64 bit), or thinking that int and long are the same size. Turn all the warnings on in XCode and fix all the problems; that is a good first step.
     
  12. macrumors 603

    Joined:
    Aug 9, 2009

Share This Page