Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!samsung!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!nucsrl!tellab5!balr!clrcom!rmartin From: rmartin@clear.com (Bob Martin) Newsgroups: comp.lang.c++ Subject: Re: Unwelcomed Standard Conversion Message-ID: <1991Apr19.130358.5067@clear.com> Date: 19 Apr 91 13:03:58 GMT References: <1991Apr12.153946.21003@urbana.mcd.mot.com> Organization: Clear Communications, Inc. Lines: 48 In article <1991Apr12.153946.21003@urbana.mcd.mot.com> qbarnes@urbana.mcd.mot.com (Quentin Barnes) writes: >I am new to C++ and am puzzled by a standard conversion. In Lippman >on p. 160 discussing function matching by standard conversion said >that any numeric type would match any numeric type. I thought this to >be a bad idea and wrote this to test it: >++ >#include > >void ff( short v ) >{ > cout << "In short ff " << v << "\n"; >} > >main() >{ > int i = 70000; > ff( i ); >} >++ >This compiled without warnings with both G++ and cfront 2.0 and silently >truncates the integer. I could not find anything in Ellis about this. >It is certainly not "value-preserving". Bug or feature? I tried your program and got the same result. A bit frightening. Then I tried the following variation: #include void ff( short v ) { cout << "In short ff " << v << "\n"; } main() { long i = 70000; ff( i ); } This complains (with a warning) about truncating the long.` I think I am going to avoid int declarations where possible. -- +-Robert C. Martin-----+:RRR:::CCC:M:::::M:| Nobody is responsible for | | rmartin@clear.com |:R::R:C::::M:M:M:M:| my words but me. I want | | uunet!clrcom!rmartin |:RRR::C::::M::M::M:| all the credit, and all | +----------------------+:R::R::CCC:M:::::M:| the blame. So there. |