PDA

View Full Version : Apps that work with XCode 3.1, crash with 3.2




Appleness
Nov 5, 2009, 12:17 PM
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



kainjow
Nov 5, 2009, 12:19 PM
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).

Cromulent
Nov 5, 2009, 12:22 PM
It might be a 64 bit versus 32 bit issue if you are building in Xcode 3.2.

What does the debugger say?

Appleness
Nov 5, 2009, 12:34 PM
The debugger says:

GDB: Program received signal: "EXC_BAD_ACCESS"

Cromulent
Nov 5, 2009, 12:39 PM
The debugger says:

GDB: Program received signal: "EXC_BAD_ACCESS"

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

Appleness
Nov 5, 2009, 12:47 PM
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];

Cromulent
Nov 5, 2009, 01:05 PM
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.

Appleness
Nov 5, 2009, 01:21 PM
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.

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

chown33
Nov 5, 2009, 01:48 PM
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.

Appleness
Nov 6, 2009, 06:32 AM
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.

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)

gnasher729
Nov 6, 2009, 10:17 AM
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)

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.

chown33
Nov 6, 2009, 10:19 AM
http://developer.apple.com/documentation/Darwin/Conceptual/64bitPorting/index.html