473,410 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

implicit conversion of bool to int

tim
We've started to use a coding standards checker at work. The following
code results in a warning:

38: CPlainText::CPlainText(const char *szPath,bool bTimeStamp,bool
bSaveLast)
39: :CLog()//call base class constructor to initialize members
40: {
41:
42: m_bTimeStamp=bTimeStamp;
43: try
44: {
45:
46:
47: if( true == bSaveLast )
^
Msg(2:3051) Be aware that an implicit conversion from 'bool' to 'int'
takes place.
48: {
49: CLog::SaveLastRunLog( szPath );
50: }
51:
The warning is flagged at line 47. Since the parameter is type bool,
and the 'true' is a bool, is there an implicit conversion taking place?

Yes, I've just spotted that the sub-class attributes arent in the
initialization list :(

===

I'm also interested in how others have found coding standard checkers.
Have they improved productivity, maintainability?

Thanks

Tim

Dec 3 '05 #1
2 6282
ti*@DELETEMErobotcrazy.com wrote:
We've started to use a coding standards checker at work. The following
code results in a warning:

38: CPlainText::CPlainText(const char *szPath,bool bTimeStamp,bool
bSaveLast)
39: :CLog()//call base class constructor to initialize members
40: {
41:
42: m_bTimeStamp=bTimeStamp;
43: try
44: {
45:
46:
47: if( true == bSaveLast )
^
Msg(2:3051) Be aware that an implicit conversion from 'bool' to 'int'
takes place.
48: {
49: CLog::SaveLastRunLog( szPath );
50: }
51:
The warning is flagged at line 47. Since the parameter is type bool,
and the 'true' is a bool, is there an implicit conversion taking place?
Yes. bool is an integral type (3.9.1p7), which means it undergoes integral
promotions (3.9.1p6). This in turn means that bool values get converted to
int when using comparison operators on them (13.6p12).
So true and bSaveLast are first both converted to int, and then the results
are compared.
I'm also interested in how others have found coding standard checkers.
Have they improved productivity, maintainability?


Sorry, I have no experience with any of those.

Dec 3 '05 #2
* ti*@DELETEMErobotcrazy.com:
We've started to use a coding standards checker at work. The following
code results in a warning:

38: CPlainText::CPlainText(const char *szPath,bool bTimeStamp,bool
bSaveLast)
39: :CLog()//call base class constructor to initialize members
40: {
41:
42: m_bTimeStamp=bTimeStamp;
43: try
44: {
45:
46:
47: if( true == bSaveLast )
^
Msg(2:3051) Be aware that an implicit conversion from 'bool' to 'int'
takes place.
48: {
49: CLog::SaveLastRunLog( szPath );
50: }
51:
The warning is flagged at line 47. Since the parameter is type bool,
and the 'true' is a bool, is there an implicit conversion taking place?
Yes, AFAICT. bool is an integral type, an integral type is an
arithmetic type, and '==' applies the "usual arithmetic conversions" on
operands of arithmetic and enumeration type. The usual arithmetic
conversions include integral promotion, which includes the conversion
bool -> int.

Instead of 'true == something', write just 'something'.

Btw., I wouldn't name a boolean "timestamp", because that is just an
association, that it's somehow related to timestamping. And I would
certainly not use Hungarian notation! E.g, name it 'm_addTimestamp'.

Yes, I've just spotted that the sub-class attributes arent in the
initialization list :(


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 3 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Simon Ford | last post by:
Hi All, I'm having trouble understanding exactly how I can do some specific implicit casting. There are two problems here; does anyone know what I should be doing? //---------- // (1)...
3
by: Boris | last post by:
Hello, I have written a program that compiles just fine with GCC 3.3. With GCC 3.4.1 it results in this error: g++ -O0 -g3 -Wall -c -oTestp.o ../Testp.c .../Testp.c: In function `int main()':...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
9
by: Girish | last post by:
Im trying to understand implicit type conversions from object -> string and vice versa. I have two classes, one Driver and one called StringWrapper. These are just test classes that try and...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
36
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
3
by: utab | last post by:
Dear all, I was trying to write a more complex program, and while searching for sth in my reference C++ primer, by Lippman. I had a question in the mind, see the code below #include <string>...
19
by: =?iso-8859-1?b?VG9t4XMg0yBoyWlsaWRoZQ==?= | last post by:
Coming originally from C++, I used to do the likes of the following, using a pointer in a conditional: void Func(int *p) { if (p) { *p++ = 7; *p++ = 8;
0
by: tonvandenheuvel | last post by:
Hi all, please consider the following piece of code: #include <iostream> template<typename T> class A { public:
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.