Optimization and template parms

Joe Buck jbuck@synopsys.com
Mon Feb 2 15:13:00 GMT 1998


>   >      In the following method of a templated class:
>   > 
>   > template <bool c>
>   > Foo<c>::f1() {
>   >   if (c) {cout << "true" << endl;}
>   >   else {cout << "false" << endl;}
>   > }
>   > 
>   >       Would I be correct to assume that after instantiating the template,
>   > egcs wouldn't emit any code for the if/else test because the test always
>   > succeeds for Foo<true> and fails for Foo<false>?

Jeff writes:
> That would be my expectation.

You would be almost correct (at least if -O is given).  However, not
quite: the strings "true" and "false" are both emitted in the executable,
although the code generated otherwise looks like just
	cout << "true" << endl;





More information about the Gcc mailing list