what does this line mean?

B

Binary

Hi,

I am curious the second half of this line:

const unsigned int ctorCount = BaseClass::GetCtorCount();
(void)ctorCount;

What is the purpose of (void)ctorCount; ?

TIA.
ABAI
 
A

Alf P. Steinbach

* Binary:
Hi,

I am curious the second half of this line:

const unsigned int ctorCount = BaseClass::GetCtorCount();
(void)ctorCount;

What is the purpose of (void)ctorCount; ?

It has no purpose except possibly in the programmer's imagination.
 
B

Bo Yang

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Binary :
Hi,

I am curious the second half of this line:

const unsigned int ctorCount = BaseClass::GetCtorCount();
(void)ctorCount;

What is the purpose of (void)ctorCount; ?

TIA.
ABAI
This line can oppress the warning of the ctorCount
was'n used .

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFPcki7tZp58UCwyMRAtBAAKCVrkBX7CIu+1y0v9C6e+KD0c77cgCg1rAt
zFmSZLdu7RZY+mCkLcVJ4zA=
=IAkv
-----END PGP SIGNATURE-----
 
P

Pete Becker

Bo said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Binary :
This line can oppress the warning of the ctorCount
was'n used .

In other words, it's a distraction caused by an over-zealous compiler. <g>

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
 
R

red floyd

Alf said:
* Binary:

It has no purpose except possibly in the programmer's imagination.

Possibly it's to shut up a compiler warning about an unused variable,
but why even make the call to GetCtorCount then?
 
F

Frederick Gotham

Binary posted:
What is the purpose of (void)ctorCount; ?


Compile the following two programs:

(1)

int main()
{
int i;
}


(2)

int main()
{
int i;

(void) i;
}


The former example might give you a compiler warning for an unused object.
 
A

Alf P. Steinbach

* red floyd:
Possibly it's to shut up a compiler warning about an unused variable,
but why even make the call to GetCtorCount then?

You mean, why store the result in an unused variable?

The only reason I can imagine is that the variable isn't unused in all
situations, i.e., that there's some conditionally compiled or
conditionally optimized away code below that uses the variable.

Which for this to make "sense" (why not move the call then) means that
GetCtorCount must have some side effect that's needed for the code
before the conditionally included code, which means it's low quality
code (side effects, conditionally included code, uncommented things)
where one shouldn't really expect any rational purpose to things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top