Why do pointers remain the same size in 64bit and 32bit systems? - pointers

I recently installed a 64bit OS on my computer, I thought that sizeof(char*) would give me 8 instead of 4. Shouldn't I get a 64 bit addresses in my pointers?

This is because the compiler you are using is emitting 32 bit code. If you use a 64 bit compiler then pointers will be 8 bytes wide.
Note that most 64 bit systems have the ability to run 32 bit code under an emulation layer. On Windows the emulation layer is known as WOW64. This is clearly what is happening here.

The OS typically has no effect on code generation. If you run the same compiler and the same libraries, you will get the same code out, regardless of whether the OS is 32-bits or 64-bits. You can compile and run 32-bit software on a 64-bit OS. You can compile 64-bit software on a 32-bit OS.
The compiler determines the type of code generated. The OS only determines whether you can run it.

Yes, you should, but note that a same operating system can run both 32-bit and 64-bit code, and that in the "64bit OS" you installed, the "64bit" may only mean "64bit able".
You really should give more detail here about the particulars of the OS. Mac OS X Snow Leopard , for instance, comes with versions of GCC and Clang that default to 64-bit code, and you can use option -m32 to generate 32-bit code. Perhaps the convention is reversed on your 64-bit OS (that is, you should use -m64 or a similar option)

Related

Making program work on 32 bit Window OS

I have written a program in Java on a 64 bit Window OS, but now I need my program to work on a 32 bit Window OS. How can I do this? (For making an exe file I used launch4j)
For Java, if the machine has the Java 32-bit is installed, then running the exe alone will be enough. If you want to provide redistributable, just use the java 32-bit redistributable.

Bitness of the system on Vala

As for the Vala language cross-platform to know the bitness of the system?
sizeof(void*) will be 8 for 64-bit systems and 4 for 32 bit systems. Also, 2 for 16 bit systems, but I don't even know that glib will work there.
The whole point of GLib is to avoid having to do platform specific code.
However according to you comment you want to do something like download platform specific packages.
First of all it would be better to use a system or user package manager to do that, since they already know how to achieve that (DRY principle).
If you absolutely must, you can also use tools like lsb-release -a or the more general uname -a (for the kernel and arch) or some other arguments to those tools.
You can invoke them with GLibs process spawning facilities.
See also:
How to determine whether a given Linux is 32 bit or 64 bit?
And a related problem is OS detection:
Is OS detection possible with GLib?
Also since Vala is a compiled language, you could use your favorite build system to pass something like -DPlatformx64 or -DPlatformx86 to the Vala compiler (see the above link on OS detection for an example on how to use the preprocessor in Vala code).

Qt/MinGW32 memory usage limitation?

I wrote an application with Qt 4.8.1 and MinGW32 (Nokia Qt SDK). I try to load a large file with this app, but the app always crash when memory usage reach 1,868 MB. If I reduce the size of input file the app works fine. Is there any memory limitations on Qt apps or MinGW32? What should I do if I really want my app to use more memory? My windows is 64 bit.
p.s. Adding "QMAKE_LFLAGS_WINDOWS += -Wl,--stack,32000000" to .pro file won't work
Thanks very much!
p.p.s. I saw many software are capable of using 10+ GB, e.g. Matlab, how to do that on Qt apps?
Your copy of windows may be 64 bit, but MingW32 is a 32 bit compiler, so any app written with that compiler has all the standard limits inherent to 32 bit Windows. Effectively, you won't be able to get more than around 2G of memory for your app to use.
There's a method to get that up to 3G, but beyond that you need a 64 bit compiler.
2GB is limit is for process only.
You can spread your application along N processes (32-bit) to allocate N x 2GB. Operating system must still be 64-bit.

Compile Qt Project on Windows for Linux / Mac

Is it possible to compile a Qt Project on Windows for Linux / Mac?
I am using Qt 5.0.2 with MinGW and Qt Creator.
i'm not saying it is impossible but it would be really hard. g++ could be tricked into generating object files but there are many linux libraries and headers that just don't exist on mingw. Linux apps are best built on linux itself.
For QT 4.* answer is YES, that's possible, I did that ones mainly for 'research purposes' and would not do it again ever.. It takes a lot of time, a lot of hacking bit's and pieces in makefiles, configurations.. There is no ANY practical sense in doing that. It takes 40 minutes to install Linux of your taste on a virtual machine (whatever you prefer) and get proper binaries.
Same applied for MacOSX.. never did it but again I believe it can be done by building a full tool-chain only question what for =))
In our organization we have 1 server with 3 virtual machines that are responsable for cross-platform building. I think that cross-compiling on one real OS may be used only for some kind of learning process, but not for real tasks.
I finally did it with compiling and building it on each OS. It is too much effort doing it on Widnows.

Wrong Architecture when running executable from Xcode4 on UNIX

First of all, I'm very new to programming.
I have a build a program using Xcode 4 on Snow Leopard.
Architecture of the project is set to "Standard (32/64-bit intel)"
Afterwards I have exported the executable file to a UNIX computer for running.
ssh to that computer
Typing ./programname in the terminal (Of the UNIX computer) gives the following response:
Exec format error. Wrong Architecture.
The program runs just fine on my Mac laptop.
When you compile a program it will (*) be compiled for a specific platform and a specific operating system. It will also most likely be compiled against a specific set of libraries. Usually those parameters are exactly those of the computer doing the compilation (the other cases are called cross-compilation).
In other words: compiling a program on a Mac will produce a binary that runs only on a Mac (unless, again, you're doing cross-compilation). Your UNIX system (which UNIX, by the way?) has a different operating system, different libraries and probably even a different CPU architetcture.
Somewhat related: Apples advertised (or used to advertise) Mac OS X as a UNIX. While Mac OS X is certainly a UNIX-class operating system, that doesn't mean that it's binary compatible with every other UNIX-class OS out there.
* almost always, with the exception of systems designed to avoid this (e.g. Java)
Programs compiled by XCode will only run under MacOS X. Unless the "UNIX computer" in step 2 is running MacOS, the program will not be able to run.

Resources