Click here to Skip to main content
15,890,741 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Desiging in C Pin
Richard Andrew x6420-Jan-15 4:24
professionalRichard Andrew x6420-Jan-15 4:24 
GeneralRe: Desiging in C Pin
CPallini20-Jan-15 4:37
mveCPallini20-Jan-15 4:37 
GeneralRe: Desiging in C Pin
Richard Andrew x6420-Jan-15 4:46
professionalRichard Andrew x6420-Jan-15 4:46 
GeneralRe: Desiging in C Pin
CPallini20-Jan-15 5:09
mveCPallini20-Jan-15 5:09 
GeneralRe: Desiging in C Pin
Albert Holguin20-Jan-15 6:52
professionalAlbert Holguin20-Jan-15 6:52 
SuggestionRe: Desiging in C Pin
David Crow20-Jan-15 4:06
David Crow20-Jan-15 4:06 
AnswerRe: Desiging in C Pin
Richard MacCutchan20-Jan-15 5:42
mveRichard MacCutchan20-Jan-15 5:42 
QuestionAdding a second recent file list to the MFC ribbon bar Pin
Leif Simon Goodwin19-Jan-15 23:18
Leif Simon Goodwin19-Jan-15 23:18 
AnswerRe: Adding a second recent file list to the MFC ribbon bar Pin
Leif Simon Goodwin23-Jan-15 0:23
Leif Simon Goodwin23-Jan-15 0:23 
GeneralRe: Adding a second recent file list to the MFC ribbon bar Pin
Leif Simon Goodwin25-Jan-15 22:45
Leif Simon Goodwin25-Jan-15 22:45 
QuestionC++ class initialization Pin
Vaclav_19-Jan-15 14:32
Vaclav_19-Jan-15 14:32 
AnswerRe: C++ class initialization Pin
Jochen Arndt19-Jan-15 21:18
professionalJochen Arndt19-Jan-15 21:18 
GeneralRe: C++ class initialization Pin
David A. Gray8-Apr-15 20:25
David A. Gray8-Apr-15 20:25 
GeneralRe: C++ class initialization Pin
Jochen Arndt8-Apr-15 20:51
professionalJochen Arndt8-Apr-15 20:51 
GeneralRe: C++ class initialization Pin
David A. Gray9-Apr-15 11:05
David A. Gray9-Apr-15 11:05 
AnswerRe: C++ class initialization Pin
CPallini20-Jan-15 1:52
mveCPallini20-Jan-15 1:52 
AnswerRe: C++ class initialization Pin
Albert Holguin20-Jan-15 4:40
professionalAlbert Holguin20-Jan-15 4:40 
Like others mentioned this isn't the cleanest example, but I'll also take a stab at explaining some of these things...
C++
static uint32_t usb_error = 0;   // is (global) static initialized to 0 as default anyway? 
static uint32_t usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; // this state is not defined as 0 - this is OK  

Initializing a global (or a static) outside of the user function or class is always good practice. The compiler may or may not initialize for you, but why risk it.
C++
USBHost::USBHost() : bmHubPre(0) // may be a default USB hub 0 , not sure 
{
     usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; // why "initialized " again here? 
 
     init();
}

This is initializing a global that is in an undefined state back to the default. Remember that if there was an instance of USBHost that existed, he might have left the state of the variable in some unknown state. Like someone else mentioned however, this initialization does imply you should only ever have one instance of this class... otherwise you'll have a conflict with the state of this variable. With that said though, it is resetting itself, so you should be able to delete the object when not in use and make a new one when you do need it.
C#
void USBHost::init()
{
     devConfigIndex     = 0;            // USB (device ?) default index
     bmHubPre     = 0;            // is this necessary? see constructor parameter
}

init() methods are usually made when there may be a need to initialize variables outside of the constructor, or alternatively, when there are multiple constructors that all need to initialize the same variables. For example, there may be some code that gets called when the USB device gets to a certain state that requires re-initialization.... rather than destruct the object and start all over, the init() may be called to re-initialize.
GeneralRe: C++ class initialization Pin
Vaclav_20-Jan-15 6:22
Vaclav_20-Jan-15 6:22 
GeneralRe: C++ class initialization Pin
Albert Holguin20-Jan-15 6:50
professionalAlbert Holguin20-Jan-15 6:50 
GeneralRe: C++ class initialization Pin
Vaclav_20-Jan-15 16:43
Vaclav_20-Jan-15 16:43 
GeneralRe: C++ class initialization Pin
Albert Holguin21-Jan-15 3:14
professionalAlbert Holguin21-Jan-15 3:14 
GeneralRe: C++ class initialization Pin
Vaclav_21-Jan-15 16:00
Vaclav_21-Jan-15 16:00 
GeneralRe: C++ class initialization Pin
CPallini20-Jan-15 7:56
mveCPallini20-Jan-15 7:56 
GeneralRe: C++ class initialization Pin
Albert Holguin20-Jan-15 8:05
professionalAlbert Holguin20-Jan-15 8:05 
GeneralRe: C++ class initialization Pin
CPallini20-Jan-15 9:14
mveCPallini20-Jan-15 9:14 

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.