Things I’ve Learned
Things I’ve learned recently:
- Using hg log on a file that was removed will not list the revision in which the file was removed. You want hg log --removed.
- Waist Watcher sodas are sweetened with Splenda, but don’t have the metallic taste that some other diet sodas do. I especially like the Citrus Frost (grapefruit) flavor. It’s like Fresca without the hidden Aspartame. (I have bad digestive reactions to Apartame.)
- Linking libxul on my Linux machine takes between 3 and 10 seconds, but apparently this is unusual. Several other people have reported link times that can range into the minutes. I recommend buying as much RAM as you can: if your entire object directory fits in the filesystem memory cache, build speed is much faster.
- When Microsoft Visual C++ mangles function symbols, the return type is encoded in the mangled name. When GCC mangles names, the return type is not encoded:
GCC MSVC int testfunc(int) _Z8testfunci ?testfunc@@YAHH@Z void testfunc(int) _Z8testfunci ?testfunc@@YAXH@Z
This means that separate functions in different translation units may not differ only by return type. We found this trying to combine the Chromium IPC code with Mozilla:
const std::string& EmptyString()
andconst nsAFlatString& EmptyString()
differ only by return type. On Windows this links correctly, but on Linux this causes multiple-definition errors.
May 27th, 2009 at 2:08 pm
How much RAM is in your Linux machine?
May 27th, 2009 at 2:16 pm
Dan, 8GB
May 27th, 2009 at 2:47 pm
I have 4Gb in mine and it doesn’t give me any problems. I can build Firefox from scratch in ~11 minutes (with make -j8).
May 27th, 2009 at 3:00 pm
Seems to me that GCC does the right thing. How would a linker resolve a call to testfunc without assignment? (e.g. testfunc(3); ). I suppose that could be a link error in MSVC but it seems odd that you would have to assign the return value of the function to force it to use the right one. Actually the C++ ISO standard says “Function declarations that differ only in the return type cannot be overloaded.” So MSVC is being kind to you.
May 27th, 2009 at 3:15 pm
Tom: the linker doesn’t need to resolve the calls, the compiler does all that. As you note, it is a violation of C++ to have two functions in the same translation unit which differ only by return type. However, it is not immediately apparent that having functions with different return types in different translation units is a violation of the one-definition rule. Anyway, I did not mean to imply that one was incorrect; just that I found an interesting difference.
May 27th, 2009 at 4:09 pm
Ah, I see what you mean now. Thanks for explaining, it is a very interesting difference. Obviously the compiler (not the linker, duh) would be the one complaining if you made a call to EmptyString() in a module that included both definitions, which is where I was headed. But that’s not the scenario here at all.