Click here to Skip to main content
15,949,686 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
jschell23-May-24 13:17
jschell23-May-24 13:17 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
Richard Andrew x6423-May-24 14:09
professionalRichard Andrew x6423-May-24 14:09 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
Richard MacCutchan23-May-24 22:13
mveRichard MacCutchan23-May-24 22:13 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
k505424-May-24 8:55
mvek505424-May-24 8:55 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
Richard MacCutchan24-May-24 22:43
mveRichard MacCutchan24-May-24 22:43 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
jschell27-May-24 12:10
jschell27-May-24 12:10 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
Richard MacCutchan27-May-24 21:57
mveRichard MacCutchan27-May-24 21:57 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
trønderen28-May-24 5:19
trønderen28-May-24 5:19 
What you have is a set of bits, commonly called a byte/octet, a halfword, a word, ...

You declare an interpretation of the bit pattern as a character.

You declare an alternative interpretation of the same bit pattern as a small integer.

You might declare a third interpretation of it as, say, an enumeration variable. You can declare as many alternate interpretations of the bit pattern as you like. The various interpretations are independent and coexistent. It is the same bit pattern all the time, nothing changes.

Unless, of course, you call for a function that interprets the bit pattern in one specific way, and the creates another bit pattern that can be interpreted as something resembling the first interpretation made by the function. Say, the function interprets the bit pattern as an integer, and forms a bit pattern that, if interpreted as a floating point value, has an integer part equal to the integer interpretation value of the first bit pattern. Yet, even the constructed bit pattern is nothing more than a bit pattern, that can be given arbitrary other interpretations.

When you declare a typed variable / pointer / parameter, you are just telling the compiler: When I use this symbol to refer to the bit pattern, it should be interpreted so-and-so. The compiler will see to that, without making any modifications to the bit pattern, and - at least in some languages - making no restrictions on other interpretations.

A problem with some languages is that in some cases, a cast will just declare another interpretation of the bit pattern, while in other cases (other interpretations), it will create a new bit pattern. If you want full control, always interpret the same bit pattern, never create a new one, a union is a good alternative to casting.

Besides, by declaring a union, you signal to all readers of the code: Beware - this bit pattern is interpreted in multiple ways! Casting can be done behind your back, risking e.g. that a variable with limited range (e.g. an enumeration) is given an illegal value. With a union, you will be aware of this risk.
Religious freedom is the freedom to say that two plus two make five.

GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
jschell29-May-24 5:26
jschell29-May-24 5:26 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
trønderen29-May-24 6:53
trønderen29-May-24 6:53 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
charlieg21-May-24 8:02
charlieg21-May-24 8:02 
AnswerRe: Okay, real C++ question - who makes use of the auto keyword? Pin
11917640 Member 21-May-24 22:09
11917640 Member 21-May-24 22:09 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
charlieg21-May-24 23:47
charlieg21-May-24 23:47 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
11917640 Member 22-May-24 0:00
11917640 Member 22-May-24 0:00 
GeneralRe: Okay, real C++ question - who makes use of the auto keyword? Pin
charlieg22-May-24 0:05
charlieg22-May-24 0:05 
AnswerRe: Okay, real C++ question - who makes use of the auto keyword? Pin
honey the codewitch13-Jun-24 12:43
mvahoney the codewitch13-Jun-24 12:43 
Questionmfc, vs2022 compatible? Pin
charlieg17-May-24 7:21
charlieg17-May-24 7:21 
AnswerRe: mfc, vs2022 compatible? Pin
Victor Nijegorodov17-May-24 7:39
Victor Nijegorodov17-May-24 7:39 
GeneralRe: mfc, vs2022 compatible? Pin
charlieg17-May-24 7:56
charlieg17-May-24 7:56 
AnswerRe: mfc, vs2022 compatible? Pin
RedDk17-May-24 9:39
RedDk17-May-24 9:39 
GeneralRe: mfc, vs2022 compatible? Pin
charlieg17-May-24 10:51
charlieg17-May-24 10:51 
GeneralRe: mfc, vs2022 compatible? Pin
RedDk17-May-24 11:11
RedDk17-May-24 11:11 
AnswerRe: mfc, vs2022 compatible? Pin
Maximilien21-May-24 5:31
Maximilien21-May-24 5:31 
GeneralRe: mfc, vs2022 compatible? Pin
charlieg21-May-24 5:51
charlieg21-May-24 5:51 
GeneralRe: mfc, vs2022 compatible? Pin
Maximilien21-May-24 8:02
Maximilien21-May-24 8:02 

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.