C code 32 bit vs 64 bit
Source: http://www.gowrikumar.com
Problem:
The following C program segfaults of IA-64, but works fine on IA-32.
Wrong problem. Sorry for the trouble.
Problem:
The following C program segfaults of IA-64, but works fine on IA-32.
int main() { int* p; p = (int*)malloc(sizeof(int)); *p = 10; return 0; }
Update (Oct 30, 2011):
Wrong problem. Sorry for the trouble.
int* is 64 bits on a 64 bit machine, but 32 bits on a 32 bit machine. int, on the other hand, is 32 bits on both. On a 32 bit machine, this would work fine, but on a 64 bit machine it segfaults, since you are allocating 32 bits of memory, but accessing 64.
ReplyDeleteCheers...
@ravi :- doesn't matter. p is pointing to a 32 bit value... shouldn't segfault.
ReplyDeletethe above code segfaulting makes no sense whatsoever.
doesn't segfault for me at least (as in fact it shouldn't. ) i'm guessing someone used a crappy compiler that got confused as ravi points out.
pratik, can you post the original link?
I too think that Ravi's solution is wrong. It should not segfault.
ReplyDeleteYou have this problem somewhere in the middle of the page http://www.gowrikumar.com/c/index.html