0

A program that I have written in C++ in Snow Leopard (OSX v10.6) runs properly on my computer. When I copy this program into a folder on another Mac running Leopard (OSX v10.5) and Ubuntu, and run it, the program segfaults. Suddenly, none of the variables and objects are instantiated properly and I'm getting garbage data in spots where there should be no data at that point.

Has anyone encountered a similar problem or know what could be the possible cause of this?

Thanks.

Hagelin
  • 16,440
  • 5
  • 29
  • 37
  • 1
    Uninitialized variables. – Erik Mar 26 '11 at 20:40
  • 1
    It's the result of **undefined behavior**. Posting the code could help . – Mahesh Mar 26 '11 at 20:40
  • That's common. You most probably have a memory leak that is ignored (but **is** a problem anyway) in the first case. Note that the problem is most likely in your code, it has nothing to do with the platforms. Do you know how to use a debugger? – sakisk Mar 26 '11 at 20:44
  • Can you provide some more information, as where it segfaults, or a gdb backtrace? Execution on different systems should differ because the environment is not exactly the same; where you place the executable, the set of files your program uses, permissions, env vars... An example of how this could lead to a segfault is: you have a pointer to a file that doesn't exist in the system, you open the file, you don't check if the file exists, so the pointer is NULL, you use the file. – rturrado Mar 26 '11 at 20:48
  • My understanding is that by default, executables created on Snow Leopard won't necessarily run on Leopard; you have to explicitly state that you want to target Leopard as your operating system. And I don't think Mac binaries execute on non-Mac OS at all. – Neil Mar 26 '11 at 21:02
  • @Neil: I think Darwin uses the Mach-O binary format, though of course it doesn't have all the same system libraries. – dmckee --- ex-moderator kitten Mar 27 '11 at 00:58

1 Answers1

1

Run it under valgrind memcheck and see what errors it reports.

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271