|
As i see
x=20; y=35;
x = (35+1) + (20+1) // y has nev value 36
x = 57
y = (36+1) + (57+1);
y = 95;
y++ // this is add 1 to y;
++y // this 1+y, but doesn't increase y for 1.
ps: You are posting in wrong forum, you shoud Visual c++
|
|
|
|
|
bsaksida wrote: ++y // this 1+y, but doesn't increase y for 1.
|
|
|
|
|
int y=1;
x = ++y; //x is 2, y is 1;
x = y++//x is 2, y is 2;
y++; // increase y by 1
|
|
|
|
|
bsaksida wrote: x = ++y; //x is 2, y is 1;
No ! y is 2 here,too. And 2 will be assigned to x.
bsaksida wrote: y++; // increase y by 1
y will become 3 here.
|
|
|
|
|
j11Software wrote: x=y++ + x++;
Here, x(20) is added to y(35) and assigned to x(55). And then incremented(++) with 1 ie.e x is now 56. Y is incremented to 1. Y is 36 now.
j11Software wrote: y= ++y + ++x;
x(56) is incremented for 1 now x is 57. y is incremented for 1. Y is 37 now. Both are added to eqate to y. i.e. y is 94 now.
|
|
|
|
|
Very close.
This is the C equivalent of what the Microsoft compiler produces:
x = 20; y = 35;
x = y + x; // 35 + 20 = 55
x = x+1; // 56
y = y+1; // 36
y = y+1; // 37
x = x+1; // 57
y = y + x; // 94
I would like to note that you should not write code like "y = y++ + x++" because the results are undefined by the language. That is the results of a statement like "x = x++" is considered undefined and it is up to the compiler vendor to decide how to implement it.
The following C equivalent code may be produce by a different compiler:
x = 20; y = 35;
tx = x+1; // 21
ty = y+1; // 36
x = y + x; // 35 + 20 = 55
x = tx; // 21 (unexpected result)
y = ty; // 36
y = y+1; // 37
x = x+1; // 22
y = y + x; // 59
One other thing I would like to point out is that other languages, that have the '++' operator, interpret it differently.
For furthur information, try searching the Net for "i=i++".
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
The postfix operator returns the value before the operation, if i == 20, i++ returns 20, ++i return 21.
x=y++ + x++;
y= ++y + ++x;
This sort of code is an interesting exercise, but you should never write code that looks like this, in the real world.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello ,
I have written a program in VC++.Net 2003 on a laptop,
when I try to run the setup on a desktop, there is a change in the
forms size, location (appearence settings).
For e.g. On the laptop the form appears to be full screen,
but on a desktop the form is smaller.
How do I make sure , that the settings are the same independent of
the machine.
Thanks in advance for your help.
Minad
|
|
|
|
|
Users control the screen resolution as part of their "Display settings". Your form is the same "pixel size" on both machines.
led mike
|
|
|
|
|
hi all,
anybody tell me where i can find readymade library for maintaing log?
payable or not doesn't matter.
please,if anybody idea share with me.
thanks & regards
bankey khandelwal
|
|
|
|
|
|
Hi guys,
I was just wondering if it is possible to assign a value class direct to a unmanaged structure without
assigning individual variables and vice versa?
/krissi
|
|
|
|
|
kristmun wrote: if it is possible to assign a value class direct to a unmanaged structure without
assigning individual variables and vice versa?
Yes System.Runtime.Interop.Marshal class has those methods.
led mike
|
|
|
|
|
Ok, on previous posts you may have noticed that I have been playing around with processes and the like.
I have created a Console application that fires up NOTEPAD and access the menus but I need to ensure that it remains as the ForegroundWindow .
To do this I need to acquire the Handle of the process that I started then apply it to the ForegroundWindow property - this is where I am having trouble.
The following is how I start NOTEPAD then return it's MainWindowHandle which is a IntPtr :
<br />
IntPtr Hnd;<br />
<br />
Process^ Proc = gcnew Process;<br />
Proc->StartInfo->FileName = "NOTEPAD.EXE";<br />
Proc->Start();<br />
Proc->WaitForInputIdle();<br />
Hnd = Proc->MainWindowHandle;<br />
Now when I include the following line:
SetForegroundWindow(Hnd);
I get the following error when compiling:
<br />
error C2664: 'SetForegroundWindow' : cannot convert parameter 1 from 'System::IntPtr' to 'HWND'
Can I conver a IntPtr to a HWND ?
Pete
|
|
|
|
|
G'Day Pete
Give this a go
::SetForegroundWindow((HWND)(Hnd.ToPointer()));
System.IO.Path.IsPathRooted() does not behave as I would expect
|
|
|
|
|
G'Day Josh,
Yep.... look'n good.
Thanks again and have a great Xmas.
Pete
|
|
|
|
|
I am using Managed C++ (VS .NET 2003 SP1), so I can't use any of the new features in C++/CLI (VS 2005).
I have a function that needs to take in a const reference to a native class, e.g.,
void MyManagedClass::f(const UnmanagedClass& u); If I just call it straight, like (inside another member function of MyManagedClass ):
UnmanagedClass u;
f(u); then it works OK. However, I would like to call this function in another thread. I have something like this, but it doesn't work:
__delegate System::Void ThreadDelegate(const UnmanagedClass&);
UnmanagedClass u;
ThreadDelegate* td = new ThreadDelegate*(this, f);
Object* args[] = new Object*[1];
args[0] = &u;
Invoke(td, args);
The problem is passing the parameter to the delegate. I would rather not have to write a managed wrapper for my unmanaged class if it can easily be avoided. Is there any way to do what I want? I have tried putting in __nogc in various parts of the array declaration but I can't get it to compile.
--
Marcus Kwok
|
|
|
|
|
Hi All,
I have a design question and I am looking for a best way to implement it.
Say I have a method which returns a string e.g.
string str = MyMethod();
MyMethod returns a string from one of the predefined strings. Based on the return value I need to execute certain sequence of methods. I do not want to implement it using an ugly if-else statements, so what is my best bet to implement it. I am looking for something like auto dispatching based on return values. Also the number of predefined strings can go up in future, so I do not really want to touch the code everytime a new string is added.
I have thought of associative array's based solution. The array will store the string to method mapping and based on the return value the correct method will be invoked. But I am not sure if this is an elegant solution.
Can someone please guide me on how to go about for an elegant solution.
Thanks and Regards.
|
|
|
|
|
switch (str)
{
case "test1"
break;
default:
break;
}
|
|
|
|
|
Hi Bsaksida,
You cannot use strings in case statement, even if you could, you will still need to modify the code if new strings are added. What I am looking for is an independed dispatch engine.
Thanks.
|
|
|
|
|
It sounds like you are asking about a "plug-in" implementation.
psychedelic_fur wrote: the correct method will be invoked.
Well that approach would be similar to the old C function pointer technique. OO concepts introduced "interfaces" which are preferable from a design standpoint. It is also referred to as Design by Contract[^]
Anyway a simplified version of this for a "plug in" implementation could go like this:
Design one or more interfaces (see Design by Contract). Each plug-in (class) will implement one or more of these interfaces. Along with the interfaces you design a "configuration" scheme for giving the application the required information about new classes that have been installed. Then you can leverage the System.Reflection classes to dynamically instantiate an object from it's text name (basically). Using this approach you can add new classes to an application by installing a new assembly and adding the requisite information to the applications configuration file.
led mike
|
|
|
|
|
Hi, i would like to know how to go about reading and writing config files in C++/CLI.
After clicking on 'open' in the menustrip, i would like to open a config file, and after editing its contents, i would like to know how to save it.
|
|
|
|
|
http://users.volja.net/bsaksida/alt.zip[^]
Whis is my finished project, and was newer published. You can use it to translate lng files. (Design for ArtMoney) You can use it as you see fit.
point of Intrest:
Public: OpenLNG(..) //In this function it opens a file.
public: SaveTranslation(..) //in this function it saves a file
ps: This project was compiled under VS2003
|
|
|
|
|
do you know of the method in .NET 2005 that can help me work on config files?
in the config files, i need to pass string through..
basically, i need to write and read config files to store values in string.
PS:i dont know how to use your codes as i dont understand them, thanks for attaching them. (:
|
|
|
|
|
Diffrence with VS2005 and VS2003 is only syntax. But callining a function or property is same order.
1. When you says config file. Did you first think how it will look it:
examples 1:
1="this var"
example 2:
options "variable"
example 3:
Font:Arial
When you have your basic syntax for config file, then you have to write reader code, witch will split into VariableName and VariableItself
|
|
|
|