Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

why compiler make two identical code for same template type

$
0
0

For a template defined as:

struct sameT{};template <class T>void print(){/*do stuff*/}int main(){    print<sameT>();    print<sameT>();}

When I watched the machine code generated by gcc for above code, there was exactly same 2 function with same content for print. I had expected this only when i had done

print<type1>();print<type2>();

Wouldn't the compiler supposed to generate a single bunch of assembly per type. I mean to use the same function twice for both print<int>(). What am I missing?


Viewing all articles
Browse latest Browse all 22113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>