Jump to content

Assignment to bool data type


karandeep963

Recommended Posts

Hello All,

 

Whats the difference if I assign a value true to any bool type instead of using 1???

 

As per my knowledge it is better to use true instead of 1 from the point of view of that compiler would easily understand it . -- M i correct here  Q:1 

 

Does it also reduce the time taken to execute the program as it reduces the implicit conversion for data type usability : ------- M i correct here Q2:

 

Have a look at the above statement and verify it . In case of any other reason please state it.

Link to comment
Share on other sites

This is not a SystemC-specific question.

 

In C++, the data type bool has either the value "true" or "false", which are by definition converted to 1 or 0, respectively, when the boolean value is converted to an integer. Inversely, a non-zero integer value is always converted to true and a zero value converted to false.

 

This relation between boolean values and integers allows for an optimal implementation of conditional statements using the conditional jump statement from the instruction set of a common microprocessor. Therefore, the impact of an implicit conversion between integer and booleans should usually not be noticeable in the execution performance of a program.

 

"true" and "false" communicate much better your intent than some magical numerical constant.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...