|
Definitely it is not safe. Even the same compiler in different situations in the source code could produce different results, as the OP seems to have experienced. The relative order of evaluation including application of side affects isn't fully specified by the standard, so the compiler gets to pick what's convenient - and can pick differently in different places. Please do not read this signature.
|
|
|
|
|
The standard DOES have something to say on this. In the Expressions section introduction, it specifically states <quote>Except when noted, the order of evaluation of operands of individual operators is undefined. In particular, if a value is modified twice in an expression, the result of the expression is undefined except when an ordering is guaranteed by the operators involved. For example,
i = v[i++];
i = 7,i++,i++;
</quote>
[Stroustrup, 2nd ed, p492]
So it's not that the standard fails to fully specify, it specifies that the result is undefined.
|
|
|
|
|
It seems it is easy to fall into this trap especially when somebody is new to C++.
|
|
|
|
|
people seem to fall into traps like this -- when they try to be cool.
there's no good reason to combine several distinct operations into single statement.
one thing I've learned in my years is that 'cool is costly' -- you could spend many many hours trying to debug that mistake.
write it simply and clearly (and readable) -- the compiler will optimize it for you.
-p
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
Clarification/correction accepted. When I wrote "relative order ... isn't fully specified", I meant "is not fully dictated" (hence, as you say, is officially undefined) rather than "is not talked about". Please do not read this signature.
|
|
|
|
|
I have this function..
void MyFunction(BSTR* param, int nArraySize);
and I'm supposed to pass an array of string ("String1", "String2", "String3") as param. How can I do this?
|
|
|
|
|
BSTR str[10];
for (int i = 0; i < 10; ++i)
str[i] = ::SysAllocString(_T("String"));
MyFunction(str, 10);
|
|
|
|
|
I use GDI+ in my project under windows Vista/7 without any problems.
But when i try to compile the code or run the code under windows XP, the program crashes/ the compiler throw an exception.
I found that pBmp1 is NULL under the windows XP:
HBITMAP hbmp1 = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));
ASSERT(hbmp1!=NULL);
Bitmap* pBmp1 = Bitmap::FromHBITMAP(hbmp1,NULL);
ASSERT(pBmp1->GetLastStatus() == Ok);
How can i Correct it?
Best,
MJM
|
|
|
|
|
First, you need to be more clear about the error. Is it a runtime error, or compile time?
What is the error?
|
|
|
|
|
Hey, what is this? You reading over my shoulder?
L u n a t i c F r i n g e
|
|
|
|
|
|
mostafa_pasha wrote: But when i try to compile the code or run the code under windows XP, the program crashes/ the compiler throw an exception.
Which is it? Does it fail to compile, or does it crash when you run it? If it fails to compile, what is the specific error message?L u n a t i c F r i n g e
|
|
|
|
|
first, it is runtime error!
I said that when i debug the code under windows XP! (it means i can compile and run the program), pBmp1 which is the GDI+ object is NULL!!! but under windows vista/7, All is OK.
My program is MDI. My project setting is USED MFC LIBRARY AS SHARED DLL!
Does it depend on the updates for windows XP or Not?
Best,
MJM
|
|
|
|
|
mostafa_pasha wrote: I said that when i debug the code under windows XP! (it means i can compile and run the program), pBmp1 which is the GDI+ object is NULL!!!
Noooo, you said this:
mostafa_pasha wrote: But when i try to compile the code or run the code under windows XP, the program crashes/ the compiler throw an exception.
There is a difference, although I take it from the second post that the first was incorrect; that is, you say now that you CAN compile under XP.
mostafa_pasha wrote: My program is MDI.
Probably irrelevant.
mostafa_pasha wrote: My project setting is USED MFC LIBRARY AS SHARED DLL!
Again, probably irrelevant, although you could build the project with MFC linked as a static library to eliminate the possibility.
mostafa_pasha wrote: Does it depend on the updates for windows XP or Not?
Perhaps; I don't know if the GDI+ runtime was affected by any updates, but it's always advisable to make sure your system is fully up to date. If it isn't, that's a good place to start, although I wouldn't hold out TOO much hope.
Have you tried using LoadImage instead of LoadBitmap? LoadImage will allow you to specify that you want the image loaded as a DIBSection, which is device independent. (Are your display settings different in XP? LoadBitmap tries to load the image in a display-compatible format; LoadImage might get you around any problem associated with this.)L u n a t i c F r i n g e
|
|
|
|
|
I think you can debug into Bitmap::FromHBITMAP() function and see what is going wrong.
|
|
|
|
|
return NULL
It means can not initilaize Bitmap!!!
Does it mean it can not initialize the GDI+?
inline Bitmap*
Bitmap::FromHBITMAP(
IN HBITMAP hbm,
IN HPALETTE hpal
)
{
return new Bitmap(hbm, hpal);
}
|
|
|
|
|
mostafa_pasha wrote: return NULL
If it returns NULL then it means the function failed and you should use GetLastError() to find out why. Incidentally the code above is somewhat different from the code in your original message. Try to use exactly the same code and trace through it with the debugger noting all the values of your variables.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
the code is here:
HBITMAP hbmp1 = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));
ASSERT(hbmp1!=NULL);
Bitmap* pBmp1 = Bitmap::FromHBITMAP(hbmp1,NULL);
hbmp1 0xb8051055
pBmp1 0x00000000
in LoadBitmap function:
inline Bitmap*
Bitmap::FromHBITMAP(
IN HBITMAP hbm,
IN HPALETTE hpal
)
{
return new Bitmap(hbm, hpal);
}
void* (operator new)(size_t in_size)
{
return DllExports::GdipAlloc(in_size);
}
in_size = 16
return 0x000000000
Best,
MJM
|
|
|
|
|
In your call to Bitmap::FromHBITMAP(hbmp1,NULL); you have given NULL as the second parameter; are you sure this is correct? The documentation here[^] says this must be the handle to a GDI palette. You should also use GetLastError() as I suggested previously to check why the call failed.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
You can actually debug further into Bitmap() constructor to see what is happening there.
I hope you have already initialized GDI+ by calling GdiplusStartup() function and checking it's return value.
|
|
|
|
|
Hi All,
Using Visual Studio 2005 C++ to create an WMP visualization.
I have an array of values id like to create checkboxes for dynamically.
i.e. the array contains the enumerated com ports on computer. i want to be able to select an checkbox and store the value.
Example
comports[5] = {"COM1","COM2","COM3","COM4","COM5"};
need to create an checkbox for each value in the array with the value as the dialog text
Any ideas?
p.s. using atl in the project
|
|
|
|
|
Something along these lines -
CButton buttons[5];
comports[5] = {"COM1","COM2","COM3","COM4","COM5"};
CRect rect;
for (int i = 0; i < 5; i++)
buttons[i].Create(comports[i], BS_AUTOCHECKBOX,&rect, this, FIRST_BUTTON_ID + i);
Alternatively, you can just use SetWindowText to ... errr ... set the window text. If you don't know ahead of time how many buttons there will be, use a dynamic array of CButtons and instantiate each individually before calling it's 'Create' member function.
And of course you'll have to initialize the CRect with appropriate values.L u n a t i c F r i n g e
|
|
|
|
|
So what exactly do you need help with? Creating the checkboxes, selecting one, or storing a value?
|
|
|
|
|
Bit of the first and last bits.
Need help creating the checkboxes from the array.
Then i need to store the dialog values in an array to be used later. I've got the basics of the array etc, My main problem is creating the checkboxes from the array
|
|
|
|
|
Steven Foxton wrote: Need help creating the checkboxes from the array.
Did you see here?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|