Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15133 > unrolled thread
| Started by | Qi <no@no.com> |
|---|---|
| First post | 2012-04-02 19:16 +0800 |
| Last post | 2012-04-05 14:17 +0800 |
| Articles | 8 on this page of 28 — 18 participants |
Back to article view | Back to comp.lang.c++
Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Qi <no@no.com> - 2012-04-02 19:16 +0800
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2012-04-02 13:39 +0200
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Victor Bazarov <v.bazarov@comcast.invalid> - 2012-04-02 09:49 -0400
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Qi <no@no.com> - 2012-04-02 22:01 +0800
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Victor Bazarov <v.bazarov@comcast.invalid> - 2012-04-02 11:50 -0400
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Paul N <gw7rib@aol.com> - 2012-04-02 12:54 -0700
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Juha Nieminen <nospam@thanks.invalid> - 2012-04-03 05:27 +0000
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-04-03 08:02 +0000
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Juha Nieminen <nospam@thanks.invalid> - 2012-04-03 14:19 +0000
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Mike McCarty <mcmccarty@gmail.com> - 2012-04-02 06:43 -0700
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? GM <GM@no.spam.it> - 2012-04-02 14:41 +0200
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? bartek szurgot <basz@no.spam> - 2012-04-02 16:55 +0200
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Juha Nieminen <nospam@thanks.invalid> - 2012-04-03 05:28 +0000
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Qi <no@no.com> - 2012-04-03 13:54 +0800
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Juha Nieminen <nospam@thanks.invalid> - 2012-04-03 14:09 +0000
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Robert Wessel <robertwessel2@yahoo.com> - 2012-04-03 11:21 -0500
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? bartek szurgot <basz@no.spam> - 2012-04-04 17:39 +0200
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-04-02 15:13 +0000
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? "MikeWhy" <boat042-nospam@yahoo.com> - 2012-04-02 11:37 -0500
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Qi <no@no.com> - 2012-04-03 10:29 +0800
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-04-03 06:00 +0200
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Qi <no@no.com> - 2012-04-03 13:56 +0800
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? goran.pusic@gmail.com - 2012-04-02 04:25 -0700
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? scott@slp53.sl.home (Scott Lurndal) - 2012-04-02 22:01 +0000
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Öö Tiib <ootiib@hot.ee> - 2012-04-02 07:37 -0700
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Dombo <dombo@disposable.invalid> - 2012-04-03 19:35 +0200
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Stuart Redmann <DerTopper@web.de> - 2012-04-04 11:56 -0700
Re: Need your experience: is "(void)param;" to avoid unused variable warnings well known for you? Qi <no@no.no> - 2012-04-05 14:17 +0800
Page 2 of 2 — ← Prev page 1 [2]
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Date | 2012-04-03 06:00 +0200 |
| Message-ID | <jldskr$tkm$1@dont-email.me> |
| In reply to | #15190 |
On 03.04.2012 04:29, Qi wrote:
> On 2012-4-3 0:37, MikeWhy wrote:
>>
>> I say "NOT GOOD". It does indeed silence the compiler warning, but does
>> not prevent subsequent use of that param, contrary to the expectations
>> set by silencing the warning.
>
> I did something like that.
> I (void)param first, then later I added some code to use param.
> Really not good and confusing...
Some days ago I posted the following to the thread "Any way to defer
template function overloading?":
<code>
#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
</code>
It ensures that a param designated as unused, is not used.
It seems to me that C++ questions are sort of like memes: suddenly the
same question pops up all over the place, and then it dies out, sort of.
Cheers & hth.,
- Alf
[toc] | [prev] | [next] | [standalone]
| From | Qi <no@no.com> |
|---|---|
| Date | 2012-04-03 13:56 +0800 |
| Message-ID | <jle3f4$6vj$2@speranza.aioe.org> |
| In reply to | #15191 |
On 2012-4-3 12:00, Alf P. Steinbach wrote: > > It seems to me that C++ questions are sort of like memes: suddenly the > same question pops up all over the place, and then it dies out, sort of. Not really. My other thread is about template function overloading. This thread is the only one I started about unused parameter. -- WQ
[toc] | [prev] | [next] | [standalone]
| From | goran.pusic@gmail.com |
|---|---|
| Date | 2012-04-02 04:25 -0700 |
| Message-ID | <31354286.612.1333365928233.JavaMail.geo-discussion-forums@yno37> |
| In reply to | #15133 |
On Monday, April 2, 2012 1:16:30 PM UTC+2, Qi wrote:
> Hi all,
>
> Let me show some code first,
>
> void someFunction(int param)
> {
> (void)param; // param is not used in this function. This line is
> // just to silence the compiler warning about unused param.
> }
>
> Please note the "(void)param".
> Is that usage common or well known for you?
> Or you rarely saw it? Or even it's weird to you?
Seen it. Also seen macros, coming from Microsoft, that use this trick and distinguish between NDEBUG and _DEBUG builds.
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2012-04-02 22:01 +0000 |
| Message-ID | <flper.214980$Zc4.126504@news.usenetserver.com> |
| In reply to | #15176 |
goran.pusic@gmail.com writes:
>On Monday, April 2, 2012 1:16:30 PM UTC+2, Qi wrote:
>> Hi all,
>>
>> Let me show some code first,
>>
>> void someFunction(int param)
>> {
>> (void)param; // param is not used in this function. This line is
>> // just to silence the compiler warning about unused param.
>> }
>>
>> Please note the "(void)param".
>> Is that usage common or well known for you?
>> Or you rarely saw it? Or even it's weird to you?
>
>Seen it. Also seen macros, coming from Microsoft, that use this trick and distinguish between NDEBUG and _DEBUG builds.
When using g++, you may use __attribute__((unused))
int
main(int argc __attribute__((unused)), const char **argv __attribute__((unused)))
{
return 0;
}
[toc] | [prev] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2012-04-02 07:37 -0700 |
| Message-ID | <bcabcab1-310b-4f36-88e9-1534dc492f86@s7g2000yqm.googlegroups.com> |
| In reply to | #15133 |
On Apr 2, 2:16 pm, Qi <n...@no.com> wrote:
> Hi all,
>
> Let me show some code first,
>
> void someFunction(int param)
> {
> (void)param; // param is not used in this function. This line is
> // just to silence the compiler warning about unused param.
>
> }
>
> Please note the "(void)param".
> Is that usage common or well known for you?
> Or you rarely saw it? Or even it's weird to you?
I have seen it. I understand what it does. Most often such functions
are still the stubs, "//TODO: implement it" and in such stage i don't
really care if and how the author silences the warnings.
A ready made function has both declaration (in header file) and
definition (in implementation file). I have seen that the declaration
contains the names even for unused parameters and definition does not
contain them. This is usually good enough in circumstances where the
reasons why the parameters are unused are obvious. For example a dummy
of unit tests:
All parameters unnamed and functions body ... something like ... throw
std::logic_error("*function_name_here* should not be called during
these tests.");. Everything is clear what and why.
> Just your experience is enough, no need to debate for it's good
> or bad. :-)
>
> The reason I ask this is, in my another thread, some very veteran
> C++ developers said they rarely saw that kind of usage.
> That makes me a little nervous because I used it a lot in my
> code to *improve* the code readability.
May be you should discuss the cases when and why you need these unused
parameters instead?
I have feeling that something is wrong when the unused function
parameters are so frequent in a real production code of C++ project
that "a lot" can be said and special tricks are needed. The parameters
are passed with a single purpose to waste cycles so the warning feels
to be in place there. You should consider ways how to have minimum
amount of such useless parameters. That improves both readability of
your code and performance of your product.
[toc] | [prev] | [next] | [standalone]
| From | Dombo <dombo@disposable.invalid> |
|---|---|
| Date | 2012-04-03 19:35 +0200 |
| Message-ID | <4f7b348e$0$14709$5fc3050@news.tiscali.nl> |
| In reply to | #15133 |
Op 02-Apr-12 13:16, Qi schreef:
> Hi all,
>
> Let me show some code first,
>
> void someFunction(int param)
> {
> (void)param; // param is not used in this function. This line is
> // just to silence the compiler warning about unused param.
> }
>
> Please note the "(void)param".
> Is that usage common or well known for you?
> Or you rarely saw it? Or even it's weird to you?
I have seen it before, but not frequently and usually wrapped in macro.
> Just your experience is enough, no need to debate for it's good
> or bad. :-)
>
> The reason I ask this is, in my another thread, some very veteran
> C++ developers said they rarely saw that kind of usage.
> That makes me a little nervous because I used it a lot in my
> code to *improve* the code readability.
> If it's not well known trick then it reduces code readability
> and then I'm going to change my code about that.
>
> That's not only about coding style but also about code readability.
I agree that code readability (easy to understand) is very important.
Personally I prefer to just comment out the parameter name. It is less
typing and is pretty clear even to less experienced coders. The purpose
of (void)param; will not be obvious to everyone,unless wrapped in a
macro with an obvious name.
[toc] | [prev] | [next] | [standalone]
| From | Stuart Redmann <DerTopper@web.de> |
|---|---|
| Date | 2012-04-04 11:56 -0700 |
| Message-ID | <b1989066-0504-4bf8-8384-4e60149a9062@f27g2000yqc.googlegroups.com> |
| In reply to | #15133 |
On 2 Apr., 13:16, Qi <n...@no.com> wrote:
> Hi all,
>
> Let me show some code first,
>
> void someFunction(int param)
> {
> (void)param; // param is not used in this function. This line is
> // just to silence the compiler warning about unused param.
>
> }
>
> Please note the "(void)param".
> Is that usage common or well known for you?
> Or you rarely saw it? Or even it's weird to you?
Never seen it in 15 years of C++ programming. Looks also weird to me.
Regards,
Stuart
[toc] | [prev] | [next] | [standalone]
| From | Qi <no@no.no> |
|---|---|
| Date | 2012-04-05 14:17 +0800 |
| Message-ID | <jljdds$teq$1@speranza.aioe.org> |
| In reply to | #15133 |
Thanks all for your input. Here is my update. I did a search, found more than 400 (void)param in about 35K lines of code. I removed more than 200, and found it really worth my time. Because I found even I (void) some parameters, latter I added code to use the parameter but forgot to remove the (void). That's terribly confusing and significantly reduced code readability. Now I use the commented out parameter name, void func(int /*param*/); Then there is no way to use an "unused" parameter. Safe and clear. Also I removed parameters that will never be used. There are still more than 100 (void) in my code. Most are in tool-generate code so I won't fix them otherwise I need to change the tool a lot. Others are in unit test that less harmful. -- WQ
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.c++
csiph-web