Apps that work with XCode 3.1, crash with 3.2

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

  1. macrumors member

    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


    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


    It might be a 64 bit versus 32 bit issue if you are building in Xcode 3.2.

    What does the debugger say?
  4. macrumors member

    The debugger says:

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


    That isn't very helpful without any code. Find out which line of code causes the bad access.
  6. macrumors member

    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);

    where sorteo is declared in the header file as:

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


    You can simplify your code a bit by doing this:

    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. macrumors member

    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

    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. macrumors member

    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


    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

Share This Page