|
|
|
|
|
by anonymous246
5699 days ago
|
|
You mean identical source code or identical assembly code? I would expect that compiler strip away typdef'ing so unless Foo and Bar are really different, only one copy of the code should exist. Yes, you can probably defeat this heuristic by doing a couple of pathalogical things, but I expect it work unless you're actively trying to defeat the system. |
|
e.g., std::vector<Foo * > and std::vector<Bar * > generate identical code for whatever you do, as they both only deal with the pointer, never dereference it in any way. Also, in code like
on a 32 bit platform, get<int>() and get<char* > generate the same machine code, whereas on a 64 bit platform, get<long>() and get<void * >() generate the same machine code.No C++ compiler that I'm aware of folds these cases into one; The C# generics do (not sure about non-generic code with identical final machine code). I would be surprised if idiomatic C++ code could be shortened by more than 50% by a compiler that did. However, if you write your code for column-major access, the binary can go down 90% if the compiler did that.
edit:formatting