Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Any way to defer template function overloading? Date: Mon, 02 Apr 2012 11:02:29 +1200 Lines: 40 Message-ID: <9ts545FfaaU2@mid.individual.net> References: <4f788f56$0$4347$7b1e8fa0@news.nbl.fi> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net CjuxwtjsVN02EDqJ9SflrA8SBvUTb4vnlDMk+qNRfybzQYHUIz Cancel-Lock: sha1:Snb94OS7o0T4enSbLwicthMvhzQ= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:7.0.1) Gecko/20111228 Thunderbird/7.0.1 In-Reply-To: Xref: csiph.com comp.lang.c++:15123 On 04/ 2/12 10:40 AM, Alf P. Steinbach wrote: > On 01.04.2012 19:24, Juha Nieminen wrote: >> Qi wrote: >>> int main(int argc, char * argv[]) >>> { >>> (void)argc; >>> (void)argv; >> >> This seemed like nonsensical code because it does nothing. Then I realized >> that it's an ugly hack to silence the compiler warning about unused >> variables. That's not how you do it. > > Right. I used to advocate a function template for that. But now I'd > rather use a macro, e.g. like this: > > > > #if !defined( CPP_DECLARE_UNUSED ) > # define CPP_DECLARE_UNUSED( argName ) \ > (void)(argName, void(), 0); struct argName; (void)0 > #endif > // SO user sehe: "(void)0" for semicolon > // SO user R. Martinho Fernandes, pointed out operator void() problem > // SO user Johannes Schaub, solution to operator,() problem > > > >> The proper way of getting rid of the warnings is to not name the >> parameters. If you still want to have their names visible, you can >> simply comment them out: >> >> int main(int /*argc, char** /*argv*/) > > But the names have documentary value, and those comments do not nest, > e.g. for the purpose of commenting out code. So include the names in the function declaration, but not in the definition. -- Ian Collins