From 5282778205198007154
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,857007135a18bc05
X-Google-Attributes: gidf78e5,public
From: Masao Morita <m-morita@pdss7.trc.rwcp.or.jp>
Subject: Re: static_cast to void
Date: 1999/09/12
Message-ID: <t0t906dizlg.fsf@pdss7.trc.rwcp.or.jp>#1/1
X-Deja-AN: 523964695
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <7rb6h3$48l$1@news.netmar.com>
X-Original-Date: 11 Sep 1999 18:09:31 +0900
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: ariel.ucs.unimelb.edu.au 937105224 21413 128.250.37.153 (12 Sep 1999 03:00:24 GMT)
Organization: Tsukuba Research Center, Real World Computing Partnership, JAPAN
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN9sXPOEDnX0m9pzZAQH7swF+O7AAYraAuSmhNthkNchn1SjiiEfL3CDV XMu44budY+oE3F8zS3OoXtP66+QjeaPz =GD24
NNTP-Posting-Date: 12 Sep 1999 03:00:24 GMT
Newsgroups: comp.std.c++

Thank you for answering my question.

> >    static_cast<void>(Any_Expression);
> >
> >This expression looks like meaningless.
> >Probably, the content of Any_expression would make sence in any case.
> >what sort of case?

> Generally casting to void is used to indicate that the (non-void) return
> value of a function call is being intentionally ignored (rather than
> accidentally overlooked).  There are some coding standards that require
> this to be done -- that the return value of a non-void function must either
> be used or explicitly discarded by casting it to void.

[snip]
> 
>         struct S { ~S(); };
>         S f();
>         int g();
>         void h() {
>             int i = (f(), g());         // #1
>             int j = ((void) f(), g());  // #2
>         }
> 
> In both #1 and #2, the temporary used for the return value of the call to
> f() is destroyed only after the call to g(); the cast to void in #2 makes
> clear that the return value of f() is being intentionally ignored, but it
> has no impact on when the temporary will be destroyed.
I am appreciated the comment.
I'm a little bit clear about "static_cast to void".

There are two practical reasons.

First one is a passive reason. It's for informing to a compliler discarding 
the expression(the return value of a fnction call). As a result of this, 
it makes avoiding accidental overlooking and suppresses the warning message
by a complier.

Second one is a more active reason. It's for calling a destructor of a 
temporary object immediately. When the calling sequence is very important,
it is useful. (I got it now!)

But, if all of reasons were above,

  static_cast<const void>(SomeExpression);

and 

  static_cast<void>(SomeExpression);

are the same meaning ( same effect )?
Is the cv-qualifier meaningless?

M. Morita
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



