Click here to Skip to main content
15,878,722 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: To bool or not to bool in C/C++ ? Pin
Vaclav_21-Feb-20 8:29
Vaclav_21-Feb-20 8:29 
GeneralRe: To bool or not to bool in C/C++ ? Pin
Richard MacCutchan21-Feb-20 22:03
mveRichard MacCutchan21-Feb-20 22:03 
GeneralRe: To bool or not to bool in C/C++ ? Pin
k505421-Feb-20 5:56
mvek505421-Feb-20 5:56 
GeneralRe: To bool or not to bool in C/C++ ? Pin
Richard MacCutchan21-Feb-20 6:07
mveRichard MacCutchan21-Feb-20 6:07 
GeneralRe: To bool or not to bool in C/C++ ? Pin
k505421-Feb-20 6:16
mvek505421-Feb-20 6:16 
GeneralRe: To bool or not to bool in C/C++ ? Pin
Richard MacCutchan21-Feb-20 6:18
mveRichard MacCutchan21-Feb-20 6:18 
GeneralRe: To bool or not to bool in C/C++ ? Pin
Vaclav_21-Feb-20 8:25
Vaclav_21-Feb-20 8:25 
GeneralRe: To bool or not to bool in C/C++ ? Pin
k505421-Feb-20 9:31
mvek505421-Feb-20 9:31 
_Bool is the standard language type. When the standard was updated, it was realized that a lot of software had already created their own definitions of "bool" (either as a #define, or as a typedef). Therefore the standards committee chose _Bool as least likely to collide with already written software (remember in C, identifiers starting with _ are reserved for the implementation, i.e. not to be used in user programs). The stdbool.h header file was mandated so that new programs could have a "sensible" bool, true and false. It should be pointed out that all the standard says about _Bool is that it be of unsigned integer type large enough to hold the values 0 and 1. In practice that means that a _Bool is a synonym for unsigned char. However, if an implementation was to give _Bool the equivalent of unsigned long int, that is perfectly acceptable. In general, the standard says what a conforming implementation must do, and guarantees it must meet, but does not state how it must do so. For example the standard says
C
sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
You can see this for yourself where in 32 bit land usually,
C
sizeof(int) = 4
sizeof(long) = 4
sizeof(long long) = 8
but in 64 bit land
sizeof(int) = 4
sizeof(long) = 8
sizeof(long long) = 8
In 16 bit land, it was often sizeof(short) == sizeof(int) == 2. This difference in sizes has caught many developers off guard when moving from 32 bit to 64 compilers, where assumptions about the size of various basic types were hard-wired into the program. Indeed, the linux kernel and associated libs are still dealing with this in terms of time_t moving from a 32 bit value to 64. For example, the range of a 64 bit time_t is approximately +/- 2.9E11 years. That means converting a large value of time_t to a struct tm currently has problems since struct tm defines tm_year as an int, which jas a range of approx. +/- 2.1E9, which is smaller by a factor of ~100. That's probably not an issue I will ever need to deal with, but I would not be surprised if something, somewhere is making assumptions about converting time_t to struct tm that's going to produce unexpected results based on "max value" of a time_t.
AnswerRe: To bool or not to bool in C/C++ ? Pin
leon de boer21-Feb-20 11:55
leon de boer21-Feb-20 11:55 
GeneralRe: To bool or not to bool in C/C++ ? Pin
Vaclav_22-Feb-20 5:34
Vaclav_22-Feb-20 5:34 
GeneralRe: To bool or not to bool in C/C++ ? Pin
Richard MacCutchan22-Feb-20 6:47
mveRichard MacCutchan22-Feb-20 6:47 
GeneralRe: To bool or not to bool in C/C++ ? Pin
leon de boer23-Feb-20 5:29
leon de boer23-Feb-20 5:29 
GeneralRe: To bool or not to bool in C/C++ ? Pin
Richard MacCutchan23-Feb-20 6:08
mveRichard MacCutchan23-Feb-20 6:08 
GeneralRe: To bool or not to bool in C/C++ ? Pin
Victor Nijegorodov23-Feb-20 20:43
Victor Nijegorodov23-Feb-20 20:43 
GeneralText based mining game using if and while Pin
Chleba22519-Feb-20 10:41
Chleba22519-Feb-20 10:41 
GeneralRe: Text based mining game using if and while Pin
Stefan_Lang19-Feb-20 21:42
Stefan_Lang19-Feb-20 21:42 
GeneralRe: Text based mining game using if and while Pin
Vaclav_20-Feb-20 17:04
Vaclav_20-Feb-20 17:04 
GeneralRe: Text based mining game using if and while Pin
Chleba22521-Feb-20 20:32
Chleba22521-Feb-20 20:32 
SuggestionRe: Text based mining game using if and while Pin
David Crow24-Feb-20 3:44
David Crow24-Feb-20 3:44 
QuestionCannot open file 'hid.lib' in microsip Pin
Jafar_Ulla19-Feb-20 2:14
professionalJafar_Ulla19-Feb-20 2:14 
AnswerRe: Cannot open file 'hid.lib' in microsip Pin
CPallini19-Feb-20 2:51
mveCPallini19-Feb-20 2:51 
QuestionUse of string class in c++ Pin
Awantika Singh14-Feb-20 21:26
Awantika Singh14-Feb-20 21:26 
AnswerRe: Use of string class in c++ Pin
Victor Nijegorodov14-Feb-20 21:35
Victor Nijegorodov14-Feb-20 21:35 
AnswerRe: Use of string class in c++ Pin
Stephane Capo14-Feb-20 21:38
professionalStephane Capo14-Feb-20 21:38 
GeneralRe: Use of string class in c++ Pin
Awantika Singh15-Feb-20 4:27
Awantika Singh15-Feb-20 4:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.