|
Hi there I am trying to understand some C++ code. I know the code below outputs "k=3 l=4". I would've thought that "++k+ ++k" would evaluate to "6", I don't see how "l" equals "4", can anyone explain this to me?
<br />
<br />
void main()<br />
{<br />
int k=3;<br />
int l;<br />
<br />
l = sizeof(++k+ ++k);<br />
<br />
printf("k=%d l=%d", k ,l);<br />
}<br />
<br />
Thanks in advance.
|
|
|
|
|
|
CaptainChainsaw wrote: Hi there I am trying to understand some C++ code.
It's actually just C; nothing C++ about it.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
l = 4 because the sizeof function returns the length in bytes of a data structure or primitive. k is an integer and integers on your machine are 4 bytes long.
|
|
|
|
|
c/c++ does not define syntax for result - avoid things like that always.
|
|
|
|
|
Hi all, thank you for your replies. I understand what is going on now!
Cheers!
|
|
|
|
|
CaptainChainsaw wrote: l = sizeof(++k+ ++k);
The sizeof is returning the size of an integer (4 bytes).
The expression ++k + ++k is undefined in the standard, but on most compilers will result in k = 5 (with an initial value of 3). That said, you should avoid using such expressions as they are both undefined and make your code highly unreadable.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi.
I'm developing a MFC ActiveX Control with some buttons on it, and I want to show some tooltips for each control.
Well, I used the code that MSDN help, offer for showing tooltips for control in a dialog box, (using CTooltipCtrl) but it did not work. Just nothing happened.
Where is the problem? Maybe, because I have COleControl derived class instead CDialog class.
Thank you.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
I will go ahead and ask the obvious. Did you override PreTranslateMessage?
Oh... just read Active X control. I do not know if PreTranslateMessage applies in this case. Might be worth a look though.....
|
|
|
|
|
Can anyone tell me how to use the MSFlexGrid control in Visual C++ 2005 or point me to any articles about the subject.
Thank you.
|
|
|
|
|
There is related [^] article, targetd to VS 2003. But should usefull to you.
|
|
|
|
|
Can somebody tell me how to create a border for dialog which is rounded rectangle.
plz provide an example.
|
|
|
|
|
A dialog already has a border, but if you are setting the window region to be a rounded rectangle, the border will not be correctly displayed. The best way to draw a border would be to create two rounded rectangles, one a little smaller than the other. From this you will be able to create a region, which you can give a color by calling FillRegion() .
|
|
|
|
|
Is there any better way. As i have more than 100 dialogs and for each dialog drawing two rect's and filling region may not be better solution.
if the dialog is rectangle i m doing as,
CRect rectWindow;
//CDC *pDC;
CPen BlackPen(PS_SOLID, 1, RGB(0, 0, 255)), *pPrevPen;
pDC = GetWindowDC();
GetWindowRect(rectWindow);
INT iLeft = 0,
iTop = 0,
iRight = rectWindow.Width() - 1,
iBottom = rectWindow.Height() - 1;
pPrevPen = pDC->SelectObject(&BlackPen);
pDC->MoveTo(iLeft, iTop);
pDC->LineTo(iLeft, iBottom);
pDC->LineTo(iRight, iBottom);
pDC->LineTo(iRight, iTop);
pDC->LineTo(iLeft, iTop);
pDC->SelectObject(pPrevPen);
ReleaseDC(pDC);
in OnCtlColor and it works well but for rounded rectangle...
-- modified at 13:35 Tuesday 5th December, 2006
|
|
|
|
|
Raj Gopal wrote: As i have more than 100 dialogs and for each dialog drawing two rect's and filling region may not be better solution.
You could make a CRoundedRectDialog class derived from CDialog. Do all your specialized
drawing there in that one class and derive your 100+ dialogs from this new dialog class.
Also, OnCtlColor gives you a chance to change the color of CONTROLS before they are drawn.
You may want to do your dialog drawing in WM_PAINT/WM_ERASEBKGND/WM_NCPAINT handlers instead.
Doing it in OnCtlColor the performance will be bad since it's called before EVERY control is drawn,
every time
|
|
|
|
|
you are right mark that is good idea.
i have one doubt.. why dont i find all the messages like WM_DRAW, WM_ERASEBKGROUND.... in the class wizard. how do i get all the message?
can you provide me some sample that changes all the controls color including dialog, so that it looks good.
|
|
|
|
|
Raj Gopal wrote: why dont i find all the messages like WM_DRAW, WM_ERASEBKGROUND.... in the class wizard. how do i get all the message?
What version of Visual Studio? In 2003 they are in the class properties under messages.
You can always add handlers the old-fashion way too (in the code editor).
Raj Gopal wrote: can you provide me some sample that changes all the controls color including dialog, so that it looks good.
What kind of look are you going for? Color changes are fairly simple except for muli-part
controls like combo boxes, trackbars, etc. Custom shaped controls will take more work since
you'll have to draw them yourself.
For the background of dialogs you can go with simple color change or use a bitmap.
|
|
|
|
|
Hey LaHaHa! Hopefully you'll see this here. I think we broke the message board on that
long ongoing joystick thread I can't respond to you there without error anymore.
I'll continue here and hopefully you'll see this.
LaHaHa wrote: I think my problem is the initialization.
My program need to periodically do the initialization of joystick.
What makes you think this? I believe what you need to do is periodically check the status
of the joystick buttons, right? Initialization only needs to happen once.
|
|
|
|
|
Mark Salsbery wrote: What makes you think this?
fish filet?
led mike
|
|
|
|
|
Yes!!!
Apparently 512 nested message levels is all this forum software could take
*edit* spelling
|
|
|
|
|
Thank you for your help!
I think my problem is the initialization.
My program need to periodically do the initialization of joystick. Could you give me more suggestions?
Please help!
|
|
|
|
|
I'm still not sure why you think you need to initialize repeatedly.
You should (after initialization) be either periodically polling for joystick actions or
waiting for an event from the joystick.
|
|
|
|
|
If I plug the joystick after the initialization, the program cannot detect the joystick. So how can I initial the joystick without periodically do it?
Please help!
|
|
|
|
|
You'll need to make sure your initializations fail if no joystick is attached.
If it fails then maybe prompt the user to attach the device.
Is that why you had it on the timer? The timer method should work - you could set a timer to
attempt to acquire the joystick every few seconds.
I'll put together a code sample today.
Mark
|
|
|
|
|
Thank you for your help!
I am looking for your code sample.
|
|
|
|