If I compile something and want to send the binary to a friend or post it on the internet, do I need to use some special GCC arguments? Does GCC optimize the binary for my specific CPU and will it run on CPUs that are a bit different or on an other Linux distribution? What else do I need to know?
Generally just need to know the binary format (mac, pc or unix in 32 or 64 bit) and if any special libraries or driver are needed. Most desktop machines run a 64bit pc format. There are some rare formats though. Gcc's default options without optimisation should be fine. There are cross compilers that enable you to compile win binaries on unix.
It really depends on what is target system architecture.
So if you are trying to run binary on arm or ppc architectures you need to have cross compile toolchains for arm or ppc respectively.
However if you are trying to run it on another computer (which generally use pentium architecture), you can probably get away with 32 bit compatible binary as 32 bit can easily be run on 64 bit machines moreover unless you are using some proprietary technology you would be able to make it cross platform compatible.