|
Tom Archer wrote:
On what a recursive function is or when you'd use one or ...?
Blast!!! Not that!!!!
I meant, I wanted to know how a static variable was going to be useful in a recursive function!!!
Nish!!!!
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
That's a lot of excitement Nish. Are you sure you're taking your Lithium like you're supposed to
If you write a function that can call itself (a recursive function) one way to maintain state information is via static variables because they won't reinitilaize in the function's prolog.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Tom Archer wrote:
Are you sure you're taking your Lithium like you're supposed to
Gosh! Not that old AI bot thing again
Tom Archer wrote:
If you write a function that can call itself (a recursive function) one way to maintain state information is via static variables because they won't reinitilaize in the function's prolog.
I thought of that actually. But I thought since it was Tom Archer saying it, there ought to be a more complicated explantion to it
Didn;'t think that the obvious one would be the only one.
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
Sometimes even I can't over-complicate something Seriously, maintaining state information across call boundaries is the main reason for using static variables within a method.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Tom Archer wrote:
On what a recursive function is or when you'd use one or ...?
I think this is Tom trying to be funny.
Nick Parker
|
|
|
|
|
And can lead to several multithreaded problems if not carefully coded...
Crivo
Automated Credit Assessment
|
|
|
|
|
Static variables sometimes are very usefull. You can use it or not... but in my opinion programmer should decided what he wants to use (in this case simply language dosn't support it - that's a pity)
Tomiga
|
|
|
|
|
The language supports class scope static variables; I don't see any reason why it should go any further. I have yet to see an instance, from an OOP standpoint, where it would beneficial to do otherwise.
Regards
|
|
|
|
|
Tom Archer wrote:
Don't you find that omission completely indefensable?
Yes, while you can fake it by putting static variables in the class; it doesn't do anything for variables you would like to keep localized only to the method.
Maybe we can see it in v.next?
James
Simplicity Rules!
|
|
|
|
|
In C++, static locals are shared among all instances of a class, not very useful for state information of a recursive function. I don't know if a C# incarnation would follow the same pattern. In C++ I have never found a good reason to use the feature unless it was for returning the reference to a static object that required more aggressive initialization than just plain assignment or to defer potentially expensive initialization of such an object until it was actually used (which could be never).
Regards
|
|
|
|
|
Neil Van Note wrote:
In C++, static locals are shared among all instances of a class, not very useful for state information of a recursive function.
Doh! You're right here; guess a regular class-level variable would be the solution
James
Simplicity Rules!
|
|
|
|
|
Neil Van Note wrote:
In C++, static locals are shared among all instances of a class, not very useful for state information of a recursive function.
I disagree. You're making the assumption that the class will be instantiated many times.
Neil Van Note wrote:
In C++ I have never found a good reason to use the feature
One example is how window procs were/are written without MFC. Another example if when iterating over a chain of entities where each function call works on a given link and a static variable is used to keep track of current position.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Tom Archer wrote:
I disagree. You're making the assumption that the class will be instantiated many times.
In this case, I am. And you are assuming the class is a singleton, this was not noted in the discussion, and I have to assume that it is not and point the fact out. I code very defensively.
Tom Archer wrote:
One example is how window procs were/are written without MFC
What does a local static have to do with the implementation of a class borne window procedure? This can be achieved very easily without it, and prove to be much more reusable.
Tom Archer wrote:
Another example if when iterating over a chain of entities where each function call works on a given link and a static variable is used to keep track of current position
I cannot picture a situation where it would be used this way and prove more elegant than other straight forward solutions. Do you have an example?
Regards
|
|
|
|
|
IIRC, there are two reasons we didn't do it:
1) You don't get much additional utility over an instance or static variable.
2) They tend to cause subtle problems when you start dealing with multi-threaded use. They're also harder to find when you're looking for such issues.
|
|
|
|
|
I was added an ActiveX control (MSChart) to my C# project and during running an exception is raised:
An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "MainForm.resources" was correctly embedded or linked into assembly "Analyzer".
baseName: MainForm locationInfo: Analyzer.View.MainForm resource file name: MainForm.resources assembly: Analyzer, Version=1.0.854.24542, Culture=neutral, PublicKeyToken=null
What should I do (step by step solvation if possible, please)
|
|
|
|
|
Welcome
How to show dialog which allows user to choose data source befor open connection to database.
Using Visul C++ you can do:
conn.Open(NULL)
and what about C#
(I use SqlConnection class)
Tomiga
|
|
|
|
|
I had just read the article "Runtime C# Expression Evaluator" in codeproject.
It seems the compiler of C# or other .net language can be called by user program. Maybe it is possible to make new .net application customized by prepareing a interface to accept outside script (any language). Then user program call the comiler to compile the script as a plugin. Then we can have plugins by any language you like.
can it be realized?
|
|
|
|
|
If I understand you correctly, you're asking if it's possible to add scripting language capabilities to unmanaged application that accept .NET languages.
The answer is Absolutely! In order to implement this, you need to write a "CLR host" for the unmanaged application. In fact, Yukon - the next version of SQL Server - is still unmanaged, yet will allow users to program stored procedures with .NET languages (instead of being confined to using TSQL).
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Thank for your info.
My English is rather limited.
What i really mean is if we create a fairly large application, we will need some macro or plugin ability just like VBA in Word, or VBS in Visual Studio.
Now if the compiler is provided by language vender and we can call compiler in runtime and run the compiled result, then we have the capability to contain any language as a macro or plugin tool. So user will use C# or even Fortran to write plugin for NewWord.
Can it be realized?
|
|
|
|
|
nova chen wrote:
Now if the compiler is provided by language vender and we can call compiler in runtime and run the compiled result, then we have the capability to contain any language as a macro or plugin tool. So user will use C# or even Fortran to write plugin for NewWord.
Can it be realized?
Yes, but the Fortran.NET compiler would have to be on the users computer in order to use it.
You also need to expose an API/object model to the script writers so they can do something to interact with your program.
James
Simplicity Rules!
|
|
|
|
|
Is there any tools to analyse the performance of C# program? What i care about is the speed of procedures in an algorithm.
I use VS7, but can't find a tool like profiler in VC6.
Tried to write a profiler for C# like the QProfile in CodeGuru, but i find it impossible because C# doesn't accept static variable in procedure. Then measure the time cost of a single procedure is not easy, or will cost a lot (for example use a string name or a unique number as a hash key to show which procedure is the profiler reached). Any suggestion?
|
|
|
|
|
I have been using Compuware/Numega DevPartner Profiler (Community Edition). It's Free.
Still waiting for the sales rep to call back when the Studio suite is available for VS.NET, they said around june for the upgrade from version 6.6. It's not Free.
|
|
|
|
|
BTW, If you do decide to check out the afore mentioned tool, a word of warning.
The installer that I used did NOT suggest to reboot my machine after it was finished.
Reboot your machine after installing it and before you actually run it. Otherwise VS.NET might do it for you. It BSOD’d my machine.
Sorry if it already bit you, it’s just been a long time since I installed it, it slipped my mind.
Regards
|
|
|
|
|
Neil Van Note wrote:
It BSOD’d my machine.
What's "BSOD" ??
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
Blue Screen of Death, in other words windows got messed up to the point it couldn't recover.
James
Simplicity Rules!
|
|
|
|