|
C++ does no checking at runtime when doing automatic conversions. The bits from the signed int are simply crammed into the unsigned int. A negative integer has the high bit set so in the unsigned world it looks like a large number. If you set the warning level to 4, a good idea in general, with VC++ you'll get a signed/unsigned mismatch warning at compile time. You should look at all warnings to make sure you're not shooting yourself in the foot accidentally and fix them with proper casts, etc, so your compiles are totally clean. That will save you a lot of work in the long run looking for subtle bugs like the wrap around you're mentioning.
Once you agree to clans, tribes, governments...you've opted for socialism. The rest is just details.
|
|
|
|
|
Yes, it should most definitely be doing this!
What you are assigning to a variable is a bit pattern - not a value. Whether the variable is signed or not is a question of interpretation. Your interpretation! Assigning a negative constant to an unsigned variable is perfectly legitimate. As Tim Craig pointed out, you should trust your beloved and most obedient servant - the compiler. All compilers will warn you about signed/unsigned mismatch.
- turin
|
|
|
|
|
Just FYI, if you want to be sure that the author gets this message, reply to the author's post and you can refer to Craig's post, as you did in the text. The author didn't get the email, Tim Craig did.
|
|
|
|
|
Fareed Rizkalla wrote: It should be zero.
this requirement exists only in your mind.
C/C++ does not work that way
|
|
|
|
|
Hi all,
I am drawing a rectangle using LineTo(HDC hdc,x,y).
Now i planning to move or change the rectangle using mouse.
For example:If i click the mouse on the rectangle line,then i can drag the rectangle line using mouse.
Any idea will be helpful
Thanks
Raj
|
|
|
|
|
You need to capture the mouse co-ordinates as you drag and then use those values in your paint routine to redraw the rectangle either at a new position in your window or as a new size, depending on how your program is designed.
It's time for a new signature.
|
|
|
|
|
Firstly, you do not need to use LineTo to draw a rectangle.
Use the Rectangle function instead.
Secondly, you can achieve the same behavior using the CRectTracker class if you're using MFC.
|
|
|
|
|
Hi,
Thanks for your reply.The reason i used LineTo is.
I have to draw to a rectangle and rotate with the given degree.I found it hard with Rectangle function.
I am calculating the axis with the given degree and values first, and then drawing the lines with that axis to complete the rectangle.
Now i want is : If i click the mouse on any of the line on rectangle.Mouse has to ba activated so that i can move the line and resize the rectangle.'
I am confused ,how to start it.
thanks
Raj
|
|
|
|
|
hello guys...I have a strange problem. I wrote a function against a button but afterwards deleted it due to some reason in vc++.net. Now I get these errors.
error LNK2001: unresolved external symbol"public void __thiscall....."
fatal error LNK1120: unresolved externals
How do I remove them without making new app
|
|
|
|
|
The message is fairly clear, you are making a call in your code to a function whose name cannot be resolved at link time. Fix your code and rebuild.
It's time for a new signature.
|
|
|
|
|
I need more information, plast all error tip, what about the information follow "..._thiscall? "
I think maybe you delete your functions in cpp file, but you didn`t delete the declare in the *.h
maybe you declare the function as a normal function,but you implement it as call back function.
|
|
|
|
|
Carlos_never wrote: I think maybe you delete your functions in cpp file, but you didn`t delete the declare in the *.h
thanx...exactly this was the problem. I mistaken double clicked a control and then deleted it but did not know that we should delete it from the *.h file as well.
|
|
|
|
|
I am trying to access BITMAP bmBits and I can get the first member of the BYTE array.
Sort off, I am not sure if it is the real value of the color.
However, when I try to increment the pointer I get “unknown size of void*” error.
The bmBits member of BITMAP is declared (standard) as LPVOID and should point to array of bytes.The BITMAP structure was filled using
(HBITMAP)GetClipboardData(CF_BITMAP).
Could someone please explain to me what am I missing here and how to fix it.
This works:
BYTE bmp = (BYTE) pDoc->bitmap[iBITMAP].bmBits;
And this code gives me the void* error
bmpBYTE = (BYTE) pDoc->bitmap[iBITMAP].bmBits++;
Any constructive help is as always appreciated.
Thanks for reading,
Vaclav
|
|
|
|
|
A void pointer can be used to point to anything, but the compiler cannot calculate an increment size for it as there is no way of knowing what it will point to at run time. You just need to create a BYTE pointer to this array, cast the void pointer to it and use that to iterate through it thus:
PBYTE pBmBits = (PBYTE) pDoc->bitmap[iBITMAP].bmBits;
bmpBYTE = *pBmBits++;
...
It's time for a new signature.
|
|
|
|
|
Thank you for your explanation. Now I know more ( about casts) and therefore I am more dangerous to myself.
I guess in the case of BITMAP the LPVOID pointer could have been just char *
since it points to byte array anyway. But it makes it more challenging for weekend programmers like me.
Thanks again
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: the LPVOID pointer could have been just char *
Yes but I think this is to allow a general structure which can contain a pointer to any format of bitmap in the future and not just a simple BYTE array.
It's time for a new signature.
|
|
|
|
|
what if you wanted to put this in to a bitfield. I have a bit map that has one bit per pixel and measures 7x70
|
|
|
|
|
Sorry, I'm not sure I understand your question.
I must get a clever new signature for 2011.
|
|
|
|
|
I have a binary (monochrome) bitmap that is 70x7 pixels would like to put it in an array that is 70x7 as binary. I know that bit fields would be a good choice. ie:
struct
{
unsigned byte d0:1;
unsigned byte d1:1;
unsigned byte d2:1;
unsigned byte d3:1;
....
} test
|
|
|
|
|
how would you cast this pointer to a bit field?
ie:
struct 7bitfield
{
unsigned byte d0:1;
unsigned byte d1:1;
unsigned byte d2:1;
unsigned byte d3:1;
unsigned byte d4:1;
unsigned byte d5:1;
unsigned byte d6:1;
} 7bits;
The reason for asking is I have an monochrome bitmap that is 70x7 and need to retrieve the data as an array of 1's and 0's. These will be used to control the on/off state of an led display.
Thanks
|
|
|
|
|
Are you saying that the fields are packed, such that the second field starts at the last bit of the byte containing the first field and so on? Something like:
byte0 + byte1 + byte2 +
01234567|01234567|01234567|01234567
01234560123456012345601234560123
00000001111111222222233333334444 - pixel numbers
In this case you would probably need to use a BYTE pointer and adjust it manually as you traverse the array.
I must get a clever new signature for 2011.
|
|
|
|
|
Adding ButtonsGroup with subbuttons to RibbonStatusbar. the buttongroup's button have showed images,but subbuttons didn't.here is my code, It was so surprising to me.
std::auto_ptr<CMFCRibbonButtonsGroup> apSBGroup(new CMFCRibbonButtonsGroup);<br />
<br />
CMFCToolBarImages images1;<br />
images1.SetImageSize(CSize(16, 16));<br />
images1.Load(IDB_TOOLBAR_SNAPTOOL);<br />
<br />
apSBGroup->SetImages(&images1, NULL, NULL);<br />
apSBGroup->SetID(ID_GROUP_SNOP);<br />
<br />
apSBGroup->AddButton(new CMFCRibbonButton(ID_DYNA, NULL, 0));<br />
<br />
std::auto_ptr<CMFCRibbonButton> pBtSnopPt(new CMFCRibbonButton(ID_HEAD, NULL, 5));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_HEAD, NULL, 5));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_CENTER, NULL, 6));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_CROSS, NULL, 7));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_LIMIT, NULL, 8));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_PEAK, NULL, 9));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_ON, NULL, 10));<br />
apSBGroup->AddButton(pBtSnopPt.release());<br />
<br />
std::auto_ptr<CMFCRibbonButton> pBtPopCoor(new CMFCRibbonButton(ID_NUMBER, NULL, 11));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_NUMBER, NULL, 11));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_THREEOK, NULL, 12));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_THREE, NULL, 13));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_GRID, NULL, 14));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_RELATEXY, NULL, 15));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_NEWOXOY, NULL, 16));<br />
apSBGroup->AddButton(pBtPopCoor.release());<br />
<br />
m_wndRibStatusBar.AddExtendedElement(apSBGroup.release(), _T(""));<br />
|
|
|
|
|
Greetings.
I need to write a function that has the following interface:
double average (int size, double values []);
The function should return the average of the first size values in the array values.
Here's an example of what I need to accomplish.
Enter number of values to be input : 5
Enter item 1 : 22.3
Current average is 22.3.
Enter item 2 : 54.2
Current average is 38.25.
Enter item 3 : 74
Current average is 50.1667.
Enter item 4 : 83.1
Current average is 58.4.
Enter item 5 : -90.
Final average is 28.72.
|
|
|
|
|
What have you done yet to try to solve this _very_ simple school problem ? did you even try to write some code for it ? or were you expecting someone else to do it for you ?
anyway, should be quite easy with a simple loop, a couple of std::cin and std::cout , an accumulator, a counter, * and / ...
I'm certain if you try to do it by yourself, you will be so proud that you will feel ashame to even have posted this question.
M.
Watched code never compiles.
|
|
|
|
|
Since the question is just to write a function, NO, I didn't try to run a program.
I Think the answer to this is:
Double average (int size, double values []);
{return (a);} {return (a + b) / 2;} {return (a + b + c) /3;} {return (a + b + c + d / 4;}
{return (a + b + c + d + e / 5;}
I really don't have a clue what I'm doing so I'm winging it to say the least. I'm thinking the above is in the ball park because in my text book, there's a program called Average.c that goes like this:
#include <stdio.h>
double average (double a, double b);
int main(void)
{
double x, y, z;
printf("Enter three numbers: ");
scanf("%1f%1f%1f", &x, &y, &z);
printf("average of %g and %g: %g\n", x, y, average (x, y));
printf("average of %g and %g: %g\n", x, y, average (y, z));
printf("average of %g and %g: %g\n", x, y, average (x, z));
return 0;
}
double average (double a, double b)
{
return (a + b) / 2;
while(1);
}
Am I in the ball-park for the function part???
Oh ya, I have no idea what Maximilien was talking about with all the
"simple loop, a couple of std::cin and std::cout , an accumulator, a counter, * and / ..." Sounds like what adults sound like on Peanuts cartoons.
|
|
|
|