karandeep963 Posted September 10, 2013 Report Share Posted September 10, 2013 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. Quote Link to comment Share on other sites More sharing options...
maehne Posted September 10, 2013 Report Share Posted September 10, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.