On foo.com you use
_gaq.push(['_setDomainName', 'foo.com']);
_gaq.push(['_setAllowLinker', true]);
and on bar.com you use
_gaq.push(['_setDomainName', 'bar.com']);
_gaq.push(['_setAllowLinker', true]);
This includes Subdomains (whatever).foo.com and (whatever).bar.com.
If you want to link from ().foo.com to (.).bar.com or vice versa, between the different domains, then the _setAllowLinker set to true comes into play and you have to add additional code to your link (see the first tracking example in the mentioned documentation). You don't need this if you link, e.g., from a.foo.com to xyz.foo.com.
It's explained in the documentation:
A session from one domain can only be transferred to another domain via a properly configured click or form submission, or via _getLinkerURL.
The setDomainName:
This method sets the domain field of the cookie to the string provided in the parameter. With this method, you can control the domain name used by the cookie. You will ONLY have to set up linking between top-level domains because sub-domains will share the same cookies with their parents.