|
SiddharthAtw wrote:
printf ("%d %d %d %d\n", i++, ++i );
OUTPUT is - 4 4 123567 123567
The compilation start from the right to left
so first ++i is calculate and because ++ is to the left of i , it is incremented first and then used in the current statement (i was 3 now it is 4) then i ++ is calculated ,
As ++ is to the right of i , i is used first and then it is incremented so the value of i used is 4 and after the printf statement its value becomes 5
that explains the 4 4 and because in printf you put extra %d %d and no variable for them garbage is printed
Hope that helped
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
bravo this is very good explanation
|
|
|
|
|
Hi,
I am initializing the static object on heap in my code. I am wondering how do I delete it now. Do I have to explicitly delete it or its going to get destroyed on its own on program termination.
.cpp file code//////
CClassA* CClassB::m_a = new CClassA;
If I don't initialize it on heap, is it going to get deleted on program termination?
Thanks i advance..
|
|
|
|
|
If you allocate memory using new or malloc then you have to free the allocated memory using delete (if you did a new) and free (if you did a malloc)
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
Yes, the memory will get deleted on program termination since the whole address space for that process is deleted.
In general, it isn't a good idea to rely on process termination to clean up memory since it can lead to sloppy and poor memory handling (common in older Unix software). However, as long as you are careful, it isn't going to hurt you.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Tim Smith wrote:
However, as long as you are careful
If you're being sufficiently careful that you can get away with being sloppy, wouldn't it be easier to be careful and neat and tidy in the first place?
Software Zen: delete this;
|
|
|
|
|
Sometimes that is harder that one would expect. I have seen people waste days working on code to make it theoretically correct when it was functionally perfect as written.
EDIT: But, in general, I agree with your statement. But I have a big problem with people saying NEVER DO XYZ. I have seen people do things like that to a fault.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Well, all memory is reclaimed by the OS when the process exits. However the destructor for the CClassA object does not run.
As mentioned above, don't develop the habit of being sloppy. Delete the object in the appropriate place in your app's shutdown/cleanup code.
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | 1ClickPicGrabber New v2.0! | RightClick-Encrypt
You cannot truly appreciate Dilbert unless you've read it in the original Klingon.
|
|
|
|
|
Now on my program inside got 2 button and 2 dialog how I can when I press button 1 dialog 1 appear press button 2 dialog 2 appear.
I just has basic knowledge on Visual C++ If can give my are full program about this solution. Thanks...
|
|
|
|
|
Hey there.
This link: (click me) has lots of dialog examples and screenshots. For instance, one that has multiple modeless dialog boxes can be found here: (click me)
|
|
|
|
|
Hi all
I'm not a programmer but I'm looking for someone with C++ knowledge and maybe knows a little about VOB files (DVD's) to help me with my small project to play a single VOB file
I've searched high and low for help yet I just can't seem to find someone
I hope I haven't broken any rules but I can't see where else to ask for help
thankyou
|
|
|
|
|
Maybe try talking to guys from Gordian Knot project (http://gknot.doom9.org/[^]).
And what is your project exactly?
You're so cute when you're frustrated. --from 'PDA' by Interpol
|
|
|
|
|
One class, which is connected to a dialog box, is handling a OnTimer message just for that class... how can I hide the dialog box and allow the user to use the main view, which its disabled if the dialog is sent the ShowWindow(SW_HIDE)? Does the dialog box need to be a modeless , I wouild prefer it would be a modal.
I would rather not pass the SetTimer to the main view class.. it would get very messy if it did.
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
Yes the Dialog has to be Modeless
otherwise you will have to create a GUI thread (not pretty;))
BTW why not modeless ?
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
I just returned it to the main timer in the view class and gave it a different UID.
Thanks anyways... a thread would have been overboard for it.
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
HI all!
I have a very simple question to ask...
I have a small program that i play with and it very simple
it call LED program, the program have a basic function like
"Reload" the script file, "Start", "Stop", "Exit", and "Clear".
and it all work just fine but the question that i have it
how can i make the program to Start auto without click on "Start"
Every time i run the program i have to click Start then the program run the scripts
and(or) is there s way that i can add right click on the icon on the system tray and start the program, instead of open the program to main menu and click Start.
Thank in advance
Thanh
|
|
|
|
|
Try to be more precise.
If it is a dialog-based application, you can call Start() method in CYourAppDlg::OnInitDialog() .
modified on Monday, August 30, 2010 6:39 AM
|
|
|
|
|
chopeen wrote:
Try to be more precise.
If it is a dialog-based application, you can call Start() method in CYourAppDlg::OnInitDialog().
Sorry i didn't be more precise.
Yes, it is a dialog based application
here is the code that i was calling for the case to start the app when i click Start or Stop ect.,
that is in my "led.c" file
<br />
BOOL CALLBACK DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)<br />
{<br />
if(wParam==SYSTRAYBUTTON&&(lParam&3)==3) {<br />
<br />
Shell_NotifyIcon(NIM_DELETE,&nidata);<br />
ShowWindow(hDialog,SW_SHOW);<br />
<br />
SetForegroundWindow(hDialog);<br />
}<br />
<br />
switch (message) {<br />
case WM_INITDIALOG:<br />
return TRUE;<br />
case WM_COMMAND:<br />
switch(LOWORD(wParam)) {<br />
case IDRELOAD:<br />
timeKillEvent(timerid);<br />
load_cfg();<br />
curtimes=0;<br />
curframes=0;<br />
curtime=0;<br />
curframe=0;<br />
change=0;<br />
timerid=timeSetEvent(current->delay,current->delay,TimeProc,0,TIME_PERIODIC);<br />
return TRUE;<br />
case IDHIDE:<br />
ShowWindow(hDialog,SW_HIDE);<br />
Shell_NotifyIcon(NIM_ADD,&nidata);<br />
return TRUE;<br />
case IDEXIT:<br />
PostQuitMessage(0);<br />
return TRUE;<br />
case IDSTOP:<br />
timeKillEvent(timerid);<br />
return TRUE;<br />
case IDSTART:<br />
timerid=timeSetEvent(current->delay,current->delay,TimeProc,0,TIME_PERIODIC);<br />
return TRUE;<br />
case IDCLEAR:<br />
timeKillEvent(timerid);<br />
{<br />
char *buf;<br />
buf=calloc(64,1);<br />
refresh(buf);<br />
free(buf);<br />
}<br />
return TRUE;<br />
default:<br />
return FALSE;<br />
}<br />
case WM_DESTROY:<br />
case WM_CLOSE:<br />
PostQuitMessage(0);<br />
}<br />
return FALSE;<br />
}<br />
and this is what it look like when in dialog
http://thanhmai.virtualave.net/led.jpg[^]
and all i want to do it let the Program to run when i open the program.
Thanh
|
|
|
|
|
I guess that this happens when you press the Go button:
case IDSTART:<br />
timerid=timeSetEvent(current->delay,current->delay,TimeProc,0,TIME_PERIODIC);<br />
return TRUE;
Am I right? If yes, put the timerid=timeSetEvent... line in WM_INITDIALOG . You will have something like this:
case WM_INITDIALOG:<br />
timerid=timeSetEvent(current->delay,current->delay,TimeProc,0,TIME_PERIODIC);<br />
return TRUE;
This should do the trick. If it does, let me know. And if it doesn't, you can send me the code and I'll work it out.
modified on Monday, August 30, 2010 6:32 AM
|
|
|
|
|
chopeen wrote:
I guess that this happens when you press the Go button:
case IDSTART:
timerid=timeSetEvent(current->delay,current->delay,TimeProc,0,TIME_PERIODIC);
return TRUE;
Am I right? If yes, put the timerid=timeSetEvent... line in WM_INITDIALOG. You will have something like this:
case WM_INITDIALOG:
timerid=timeSetEvent(current->delay,current->delay,TimeProc,0,TIME_PERIODIC);
return TRUE;
This should do the trick. If it does, let me know. And if it doesn't, you can send me the code and I'll work it out.
Hi chopeen,
Yes, you are right it happen when you press the Go button: i have try to use your method and it didn't work it compile and when i try to run the app i get and Application Error
"The instruction at "0x00401447" referenced memory at "0x00000008". The memory could not be "read".
here is what i add to the code:
switch (message) {<br />
case WM_INITDIALOG:<br />
timerid=timeSetEvent(current->delay,current->delay,TimeProc,0,TIME_PERIODIC);<br />
return TRUE;
maybe i try it again tomorrow, right now is 4:00 AM and i just get back home from work and check the message and try it see it work but not.
here is a block section of the code that the DIALOG INIT
BOOL CALLBACK DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)<br />
{<br />
if(wParam==SYSTRAYBUTTON&&(lParam&3)==3) {<br />
<br />
Shell_NotifyIcon(NIM_DELETE,&nidata);<br />
ShowWindow(hDialog,SW_SHOW);<br />
<br />
SetForegroundWindow(hDialog);<br />
}<br />
<br />
switch (message) {<br />
case WM_INITDIALOG:<br />
return TRUE;<br />
case WM_COMMAND:<br />
switch(LOWORD(wParam)) {<br />
case IDRELOAD:<br />
timeKillEvent(timerid);<br />
load_cfg();<br />
curtimes=0;<br />
curframes=0;<br />
curtime=0;<br />
curframe=0;<br />
change=0;<br />
timerid=timeSetEvent(current->delay,current->delay,TimeProc,0,TIME_PERIODIC);<br />
return TRUE;<br />
case IDHIDE:<br />
ShowWindow(hDialog,SW_HIDE);<br />
Shell_NotifyIcon(NIM_ADD,&nidata);<br />
return TRUE;<br />
case IDEXIT:<br />
PostQuitMessage(0);<br />
return TRUE;<br />
case IDSTOP:<br />
timeKillEvent(timerid);<br />
return TRUE;<br />
case IDSTART:<br />
timerid=timeSetEvent(current->delay,current->delay,TimeProc,0,TIME_PERIODIC);<br />
return TRUE;<br />
case IDCLEAR:<br />
timeKillEvent(timerid);<br />
{<br />
char *buf;<br />
buf=calloc(64,1);<br />
refresh(buf);<br />
free(buf);<br />
}<br />
return TRUE;<br />
default:<br />
return FALSE;<br />
}<br />
case WM_DESTROY:<br />
case WM_CLOSE:<br />
PostQuitMessage(0);<br />
}<br />
return FALSE;<br />
}<br />
Thank you the help
Thanh
|
|
|
|
|
Looks like the current object (whatever it is) is not initialized, when you start your app.
It means that there is something before IDSTART that does it.
modified on Monday, August 30, 2010 6:39 AM
|
|
|
|
|
i have get it to work finally
i have to add it at the end of my loading the script file
Thank for the help chopeen.
Thanh
<br />
load_cfg();<br />
#ifdef DEBUG<br />
mem_debug();<br />
#endif<br />
<br />
{<br />
char *buf;<br />
buf=calloc(64,1);<br />
refresh(buf);<br />
free(buf);<br />
}<br />
<br />
timerid=timeSetEvent(current->delay,current->delay,TimeProc,0,TIME_PERIODIC);<br />
<br />
<br />
while (GetMessage (& msg, 0, 0, 0)) {<br />
if (!IsDialogMessage (hDialog, & msg))<br />
{<br />
TranslateMessage ( & msg );<br />
DispatchMessage ( & msg );<br />
}<br />
}<br />
<br />
<br />
Shell_NotifyIcon(NIM_DELETE,&nidata);<br />
return 0;<br />
}<br />
|
|
|
|
|
Another solution is a timer.
Kuphryn
|
|
|
|
|
thank, but i don't want to do with any timer
my program have a time delay when it open up and it init the dll driver for
parallel port and then it load the ledcfg.txt and it sit there until i click
start the program.
Thanh
|
|
|
|
|
Using Microsoft .NET 2003, Visual C++
After compiling a project, when I run the project, I get a dialogbox saying the project is out of date and if I want to comile it.
If I respond Yes, it seems to be compiling the resources. I've checked the dates of resource files, all seems ok.
What can be causing that ?
happy holidays.
|
|
|
|
|