|
It depends on the compiler, and the switch settings you apply.
A smart compiler may toss it all out as all calculations ultimately generate a value for tr which is then not used at all.
And if you were to add a function call (say print(tr); ) which makes the calculations necessary, the compiler could still discover that the tr value is a constant that can be evaluated right away at compile-time, hence tossing the other variables.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
|
In addition to previous replies, since the integers are automatic, i.e. allocated on the stack, which already has storage reserved, the memory footprint will not be affected if you add or remove such local variables, as it does not affect system resources. However, the stack will fill up quicker if you (or the compiler) add them.
|
|
|
|
|
Having finally started migrating from VS6->VS2010, we have our first attempt at internationalisation looming.
What is current best practice for foreign language versions of C++ apps? Can anyone speak from experience?
|
|
|
|
|
All you need to know is unicode.
all the text strings should be converted to unicode format.
[1]make a collection\ identify of all the readable text string on your apps gui.
[2]convert all the char buffers used to process the text strings to wchar buffers (char : 1 bytes and wchar 2:bytes)
[3]MFC CString will automatically behave as unicode when you declare your app as unicode application either by mentioning
#define UNICODE
#define _UNICODE
in stdafx.h or some global file which is accesible to all the other files.
You may also use app property dialog to declare your app as unicode.
While convering text from ansi to unicode, WideCharToMultiByte and MultiByteToWideChar APIs will be required.
this is just some hints to proceed...you may be required to do other tasks as appropriate depending upon your app.
|
|
|
|
|
Internationalisation is a huge topic, but a few pointers:
1. separate all UI strings from your code (string tables are a must in Windows)
2. do localizing into 1 other language in parallel with development to catch problems early
3. use industry standard tools (SDL, memoQ, Idiom, LocStudio if you can find it) for localizing, avoid developing your own tools
4. use the operating systems services whenever possible (NLS functions in Windows)
Good luck!
|
|
|
|
|
Thanks for this. We are starting slow, just targeting one other language to start, but obviously we want to set everything up to make adding other languages easier in future.
We'll probably try and make a resource DLL per language. Thanks for the pointers to the tools too - I didn't know such things existed, so will have to look into them.
|
|
|
|
|
"Internationalization" is not simply a matter of understanding character set representations.
Potential issues.
1. Understanding culture differences (do your custom icons represent an obscene gesture?)
2. Correct GUI layout.
3. Grammatically correct dynamic output.
4. Verifying that translated text is actually translated correctly.
5. Laws/legal matters that dictate "correct" representations. An example is that some places dictate the use of specific timezones.
|
|
|
|
|
few additional points.
1) reading style ( right to left or left to right ) most of the is taken care
2) The language script may be same in two different languages but the way its words are interpreted may be different
3) On Windows dialog specially, you have to use different dialog template since the default fonts may not render character of UI in a given language.
We face this problems in past, for Japanese font and we have to create a whole new set of dilaog boxes to maintain same look and feel of application throughout the running lifetime of application.
4) The size of executable.and code base itself, If your code works on special hardware ( like Credit card devices where limited amount of memory is available) This could be a huge problem
HTH
|
|
|
|
|
Abhi Lahare wrote: 1) reading style ( right to left or left to right ) most of the is taken
care
Tell me about it - we've already had a load of hassles getting Hebrew and Arabbic to work correctly - never mind Chinese
|
|
|
|
|
as far on windows box, all the arabic strings was acceptable to client. we have other hardware were standard font file did not work as desired and gave us a good amount of trouble. sorry I do not remember the details it was a long back 6 yrs back
In case of Japanese and Chinese ( in different project ) we build a whole set of dialog boxes with different fonts for once user select the input language.
The default (FONT 8, "MS Sans Serif") for us do not rendered the Japanese character.
HTH
|
|
|
|
|
I have created list of points.
CList<CPoint, CPoint> m_PointList;
m_PointList contains the coordinates from the screen display.
I want to find the Right most top point from the list.
For e.g List contains following points:
1)(1263,643)
2)(1258,276)
3)(1225,266)
4)(1180,257)
5)(990,241)
6)(835,239)
7)(935,705)
8)(1094,691)
9)(1258,655)
Please consider the screen coordinate system. i.e X increases from left to right and Y increase from top to bottom.
With the above input points, the output of the program should be (1258,276).
In the above mentioned points the right most point is 1263 but the corresponding y co-ordinate is 643, which is greater than the 2nd point's y co-ordinate for which the x co-ordinate is 1258.
Hence as per the display, the right most top point is (1258,643).
Please suggest the algorithm to be used.
|
|
|
|
|
Could you explain the logic more clearly? I don't understand what you are trying to do and why the 1263 rightmost point is omitted because of the second entry.
What is the algorithm supposed to do?
|
|
|
|
|
The first thing you need to decide is whether the horizontal or vertical axis has precedence. After that is a simple matter of selecting the largest value in either set.
The best things in life are not things.
|
|
|
|
|
As already noted by Richard, you have to choose the sorting order (first Y-axis or first X-axis?) otherwise the problem is ambiguous. On the other hand, if you instead need to find the 'bounding rectangle' top-right point, then the problem is well-defined but such point doesn't necessary match one of the given set.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
If I understand you correctly, you want to find the point that is the farthest ina a particular direction. By the way you ask I assume you are not looking for the rightmost or topmost point, but a point that is 'closest to the top right corner', or something like that.
I am thinking what you need is to define the direction you are looking at as a vector (in a geometrical sense), and then use vector algebra to determine which of the points is farthest in the direction denoted by that vector. To do this, you use that direction to define a line, and project all points onto that line, then determine its distance to the lines origin. It doesn't really matter where that origin lies as long as you differentiate which side of the origin your projected point comes to lie by using a signed distance value; for sake of simplicity just use (0,0) as origin.
A line through (0,0) in the direction of D can be defined by L(t)=t*D. Calculating the projection Q of a point P on this line can be done like this: Q = (P*D / |D|) * D / |D| = (P*D)*D / (D*D). Basically this formula defines the parameter t for the peojected point Q to be t(Q)=(P*D)/(D*D). For the purpose of looking for the point 'farthest' in the direction of D, you can just compare the values of t(Q). And since the denominator (D*D) is a constant, you can just ignore it. Instead just calculate P*D for each point P and determine the point with the largest result:
struct point2 {
int x;
int y;
}
int operator*(const point2& p1, const point2& p2) {
return p1.x*p2.x + p1.y*p2.y;
}
void test() {
std::list<point2> pointlist;
point2 P;
P.x = 1258;
P.y = 263;
pointlist.push_back(P);
P.x = 1263;
P.y = 260;
pointlist.push_back(P);
point2 D;
D.x = 1;
D.y = 1;
std::list<point2>::iterator it = pointlist.begin()
double farthest_value = (*it) * D;
std::list<point2>::iterator farthest_point = it;
while (++it != pointlist.end()) {
double value = (*it) * D;
if (value > farthest_value) {
farthest_value = value;
farthest_point = it;
}
}
std::cout << "farthest point is (" << farthest_point.x << "," << farthest_point.y << ")" << std::endl;
}
|
|
|
|
|
Hi,
I have a sample project where I am using a C# library in a C++ test program. I'm doing this by COM, using the tlb and project reference.
C#
<br />
[ComVisible(true)]<br />
[ClassInterface(ClassInterfaceType.AutoDual)]<br />
public class Math<br />
{<br />
public int Add(int x, int y)<br />
{<br />
return x + y;<br />
}<br />
<br />
public static int Subtract(int x, int y)<br />
{<br />
return x - y;<br />
}<br />
}<br />
C++
<br />
#include "stdafx.h"<br />
#include <iostream><br />
<br />
#import "..\\CSharpUsefulLibrary.tlb" raw_interfaces_only<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
CoInitialize(0);<br />
<br />
CSharpUsefulLibrary::_MathPtr math(__uuidof(CSharpUsefulLibrary::Math));<br />
<br />
long value;<br />
math->Add(1, 2, &value);<br />
std::wcout << "The value is " << value;<br />
<br />
CoUninitialize();<br />
return 0;<br />
}<br />
So this works fine, I'm able to call the add method in my C# library from C++. The question is, how do I call the static subtract method?
|
|
|
|
|
I'm afraid you cannot do it: There's no trace of the static Subtract method in the tlh generated file.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yeah, in VS I did File->Open on the tlb and indeed couldn't find it. Looks like we'll need a wrapper to expose static funcitons. Thanks
|
|
|
|
|
You could create a singleton object in C# project, that could provide access to the static methods.
|
|
|
|
|
There's no need, I suppose, since he already has a class. He has simply to wrap the static method with an instance one.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
newkie wrote: The question is, how do I call the static subtract method?
afaik, and my weak knowledge in COM, i haven't seen STATIC method being exported by COM model
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
|
Hi to all,
I am facing a strange problem, i had asked for help in the forum few days before. But due to certain delays i was unable to show the code. Here is the code. My Problem is with hindi fonts.
When i substitute the the LOGFONT.lfHeight with 0(Zero) then everything works fine, But when i change the size of lfHeight to anything greater or lesser than zero, the Hindi fonts is displayed very small. How to solve this issue.
case WM_INITDIALOG:
LOGFONT lf;
HFONT cFont;
HWND target = GetDlgItem(hwnd,IDC_STATIC1);
HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
GetObject(hFont, sizeof(LOGFONT), &lf);
lf.lfHeight = 0;
cFont = CreateFontIndirect(&lf);
SendMessage(target,WM_SETFONT,(WPARAM)cFont,MAKELPARAM(TRUE,0));
SetWindowText(target,_T("C:\\Program Files\\অভিধান: ইংরেজী\\सरकारी &&"));
break;
sorry for posting twice.
Regards,
Vishal
modified on Thursday, June 9, 2011 1:32 PM
|
|
|
|
|
You need to convert the point height of your font into device units with the following formula:
lFont.lfHeight = MulDiv(nFontHeight, GetDeviceCaps(hDC, LOGPIXELSY), 72);
See the MSDN page for CreateFont()[^] for more information.
The best things in life are not things.
|
|
|
|