Click here to Skip to main content
15,846,826 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to design pure C style APIs for a framework which include a core exe and plugin dlls Pin
Richard MacCutchan9-Nov-16 23:52
mveRichard MacCutchan9-Nov-16 23:52 
AnswerRe: How to design pure C style APIs for a framework which include a core exe and plugin dlls Pin
leon de boer10-Nov-16 10:06
leon de boer10-Nov-16 10:06 
GeneralRe: How to design pure C style APIs for a framework which include a core exe and plugin dlls Pin
bestbear10-Nov-16 19:11
bestbear10-Nov-16 19:11 
QuestionC programming Determine Students grade Pin
Member 128422149-Nov-16 13:37
Member 128422149-Nov-16 13:37 
AnswerRe: C programming Determine Students grade Pin
leon de boer9-Nov-16 15:27
leon de boer9-Nov-16 15:27 
QuestionHow explicit , volatile and mutable keywords works INTERNALLY in C++ ? Pin
Amrit Agr6-Nov-16 23:06
Amrit Agr6-Nov-16 23:06 
AnswerRe: How explicit , volatile and mutable keywords works INTERNALLY in C++ ? Pin
Richard MacCutchan7-Nov-16 1:18
mveRichard MacCutchan7-Nov-16 1:18 
AnswerRe: How explicit , volatile and mutable keywords works INTERNALLY in C++ ? Pin
leon de boer7-Nov-16 9:15
leon de boer7-Nov-16 9:15 
Explicit and volatile you need to know, if you are seen using mutable in C++ we put you up against the wall and shoot Smile | :)

There are a couple of places you need volatile the two main ones are in multitasking code and interfacing to physical hardware. What volatile tells the compiler the result at that address can change between uses of it ... so it stops the optimizer assuming the value hasn't changed between uses of that address.

Imagine the situation you have code that reads the port of a timer at an address. Then you do some other stuff not touching the port address and then you go an read the port again. Now if you are dealing with memory the two reads will have the same value as the code between the two reads didn't touch the port. So an optimizer might well conclude it can remove the second read and just hold the first read value. Only in reality the timer values ticks because it's hardware and so we need the second read to occur it can't be optimized. The same situation occurs in multitasking, memory that our own code didn't touch can change. So volatile is about making sure the optimizer doesn't shortcut stuff assuming just because the code hasn't touched it, that it hasn't changed. So any variable marked with volatile will have any action on that variable not subject to optimization.

Explicit is when you want the compiler to stop being smart and convert types for you and pretending it's GWBASIC Smile | :)
It used to happen mostly on class/object code that a constructor for example would take a string as a parameter. If you gave it an integer it would automatically know to convert the integer to a string, which is pretty cool sometimes. Other times it leads to a complete and utter bug because you didn't allow for it. So if you tell the compiler you want explicit it turns off the GWBASIC parser and stops the conversion it will throw an error instead.

Mutable is one you will rarely if ever need and if you do need it most of us will argue your code is badly organized or you are super lazy and dangerous. The better name for it would be cached or stencil playtime. So you have a constant or someone passes you in a constant, but you just want to change it I mean string "Drive A" is so close to "Drive B". You declare it mutable you can now play around with the constant it wont change the real constant just your local play copy. It's not something to encourage in that usage. The only real valid use of the directive is when you really are dealing with a real cache such as synchronization objects like mutexes & semaphores. It really exist solely for those unique situations and really shouldn't be abused.

Now I am being flippant so you actually take time to go read up on them properly but that is the basics.
In vino veritas

GeneralPlease help Pin
Ahmed Adel5-Nov-16 4:20
Ahmed Adel5-Nov-16 4:20 
GeneralRe: Please help Pin
Richard MacCutchan5-Nov-16 22:01
mveRichard MacCutchan5-Nov-16 22:01 
GeneralRe: Please help Pin
leon de boer6-Nov-16 5:49
leon de boer6-Nov-16 5:49 
PraiseRe: Please help Pin
Ahmed Adel6-Nov-16 6:10
Ahmed Adel6-Nov-16 6:10 
QuestionPattern review C++: using structs with pure virtual methods in place of interfaces Pin
Member 128328324-Nov-16 6:58
Member 128328324-Nov-16 6:58 
AnswerRe: Pattern review C++: using structs with pure virtual methods in place of interfaces Pin
Chris Losinger4-Nov-16 9:23
professionalChris Losinger4-Nov-16 9:23 
AnswerRe: Pattern review C++: using structs with pure virtual methods in place of interfaces Pin
leon de boer4-Nov-16 9:48
leon de boer4-Nov-16 9:48 
AnswerRe: Pattern review C++: using structs with pure virtual methods in place of interfaces Pin
«_Superman_»5-Nov-16 22:42
professional«_Superman_»5-Nov-16 22:42 
AnswerRe: Pattern review C++: using structs with pure virtual methods in place of interfaces Pin
Daniel Pfeffer6-Nov-16 1:35
professionalDaniel Pfeffer6-Nov-16 1:35 
QuestionMouse out of dialog Pin
_Flaviu3-Nov-16 5:07
_Flaviu3-Nov-16 5:07 
AnswerRe: Mouse out of dialog Pin
leon de boer3-Nov-16 5:21
leon de boer3-Nov-16 5:21 
QuestionRe: Mouse out of dialog Pin
David Crow3-Nov-16 16:42
David Crow3-Nov-16 16:42 
AnswerRe: Mouse out of dialog Pin
_Flaviu3-Nov-16 22:44
_Flaviu3-Nov-16 22:44 
GeneralRe: Mouse out of dialog Pin
Richard MacCutchan3-Nov-16 23:04
mveRichard MacCutchan3-Nov-16 23:04 
GeneralRe: Mouse out of dialog Pin
leon de boer3-Nov-16 23:10
leon de boer3-Nov-16 23:10 
GeneralRe: Mouse out of dialog Pin
_Flaviu4-Nov-16 0:12
_Flaviu4-Nov-16 0:12 
QuestionSharing some humour Pin
leon de boer2-Nov-16 6:40
leon de boer2-Nov-16 6:40 

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.