Modifies code files in a C++ project to make as many class member methods
'const' as possible. It parses the methods in all the files, tries making
them 'const', tests whether the build succeeds and if not reverts to the
previous state.
The more methods that are const, the faster the C++ program will run, as the
compiler can allocate special sections of read-only memory for things it
knows are going to be constant - this also leads to better security. The
effect is snowballing - the first pass of the program on a project may, say,
convert 5% of methods to const methods, but running a second pass may
convert some more - as methods that call the methods that have now been made
const (but came early on in the sort order) may now be able to be constified
because they are now calling const methods.
Leave the program running overnight on your project continuously in a loop,
and when you wake up in the morning, as many methods as possible will be
const! http://www.planetsourcecode.com/vb/s...3644&lngWId=10
Comments? 16 1134
Bonj wrote: Modifies code files in a C++ project to make as many class member methods 'const' as possible. [...]
That's nice. My problem with [somebody else's] const-challenged code
is usually different, though. Either some arguments are left non-const
(it's often 'char*' instead of 'char const*'), or members of classes
over which I have no control (from a 3rd-patry library) and changing
those in the headers makes no sense. Can that thing do anything about
those? It should be able to do the former, but of course not the latter.
V
First of all, let me say that it only changes member declarations in .h
files if it finds a corresponding implementation in a .cpp file in the same
directory (whereupon it changes that aswell to match) - so you should find
it doesn't touch declarations of things that are in a 3rd-party library.
I ran it on my project and out of 136 methods, it constified about 8.
The challenge facing it really now is that to increase this success rate, at
the end of the day is really going to be proportional to the amount of AI
one be bothered to add. For instance, certain methods when changed to const
would cause compilation to fail, but would succeed if certain parameters
were also changed to const at the same time - the algorithm would have to be
a lot more complex in order to marry these up in order to score a hit.
Perhaps a compromise approach would be to develop a new strain of the
program to constify parameters rather than methods, running the two
alternatively on a project could eventually force more and more things down
the road of const-ness?, sort of like zig-zagging up a mountain...
The program of course isn't particularly optimized in terms of how fast it
actually runs, obviously I'd prefer to put the effort into improving the
success rate.
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl... Bonj wrote: Modifies code files in a C++ project to make as many class member methods 'const' as possible. [...]
That's nice. My problem with [somebody else's] const-challenged code is usually different, though. Either some arguments are left non-const (it's often 'char*' instead of 'char const*'), or members of classes over which I have no control (from a 3rd-patry library) and changing those in the headers makes no sense. Can that thing do anything about those? It should be able to do the former, but of course not the latter.
V
Does this have anything whatsoever to do with C#?
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Bonj" <a@b.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... Modifies code files in a C++ project to make as many class member methods 'const' as possible. It parses the methods in all the files, tries making them 'const', tests whether the build succeeds and if not reverts to the previous state. The more methods that are const, the faster the C++ program will run, as the compiler can allocate special sections of read-only memory for things it knows are going to be constant - this also leads to better security. The effect is snowballing - the first pass of the program on a project may, say, convert 5% of methods to const methods, but running a second pass may convert some more - as methods that call the methods that have now been made const (but came early on in the sort order) may now be able to be constified because they are now calling const methods. Leave the program running overnight on your project continuously in a loop, and when you wake up in the morning, as many methods as possible will be const!
http://www.planetsourcecode.com/vb/s...3644&lngWId=10 Comments? Leave the program running overnight on your project continuously in a loop, and when you wake up in the morning, as many methods as possible will be const!
I think if you need to leave a program compile overnight,
you're either compiling Windows XP on a 286 or you're
doing something wrong =]
This program is written IN c#, FOR c++.
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:em**************@TK2MSFTNGP14.phx.gbl... Does this have anything whatsoever to do with C#?
-- Bob Powell [MVP] Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET. Subscribe to the RSS feeds provided and never miss a new article.
"Bonj" <a@b.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... Modifies code files in a C++ project to make as many class member methods 'const' as possible. It parses the methods in all the files, tries making them 'const', tests whether the build succeeds and if not reverts to the previous state. The more methods that are const, the faster the C++ program will run, as the compiler can allocate special sections of read-only memory for things it knows are going to be constant - this also leads to better security. The effect is snowballing - the first pass of the program on a project may, say, convert 5% of methods to const methods, but running a second pass may convert some more - as methods that call the methods that have now been made const (but came early on in the sort order) may now be able to be constified because they are now calling const methods. Leave the program running overnight on your project continuously in a loop, and when you wake up in the morning, as many methods as possible will be const!
http://www.planetsourcecode.com/vb/s...3644&lngWId=10 Comments?
No, I didn't say leave it compiling overnight, I said leave it running
overnight!
It takes a long time to run because it does a build with each change to a
source file it makes to see if the compiler will allow the change.
I agree if I it took overnight to compile I would have a problem, especially
C#!
"andré m.a" <a.***@videotron.ca> wrote in message
news:S0********************@weber.videotron.net...
Leave the program running overnight on your project continuously in a loop, and when you wake up in the morning, as many methods as possible will be const!
I think if you need to leave a program compile overnight, you're either compiling Windows XP on a 286 or you're doing something wrong =]
Hi Bonj! Modifies code files in a C++ project to make as many class member methods 'const' as possible. It parses the methods in all the files, tries making them 'const', tests whether the build succeeds and if not reverts to the previous state. The more methods that are const, the faster the C++ program will run, as the compiler can allocate special sections of read-only memory for things it knows are going to be constant - this also leads to better security. The effect is snowballing - the first pass of the program on a project may, say, convert 5% of methods to const methods, but running a second pass may convert some more - as methods that call the methods that have now been made const (but came early on in the sort order) may now be able to be constified because they are now calling const methods. Leave the program running overnight on your project continuously in a loop, and when you wake up in the morning, as many methods as possible will be const!
Nice project...
Just as a challange:
It would be nice if your project could also emit the new SAL annotations!
See: Header Annotations http://msdn.microsoft.com/library/de...nnotations.asp
Some annotations like "__in", "__in_opt", "__out", "__out_opt" could be
"easily" figured out only by looking into the source of the function...
--
Greetings
Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
Looks a good syntax , clearly the 'way of the future', I might have a go at
incorporating it....
Seemingly a parameter would be __out if it can't be const, and a parameter
*should* be const if it is declared __in?
Also interested to know what effect __opt has at compile time compared to
run time, since whether a 'NULL' parameter is going to be passed surely
can't always be detected at compile time?
"Jochen Kalmbach [MVP]" <no********************@holzma.de> wrote in message
news:eA**************@tk2msftngp13.phx.gbl... Hi Bonj! Modifies code files in a C++ project to make as many class member methods 'const' as possible. It parses the methods in all the files, tries making them 'const', tests whether the build succeeds and if not reverts to the previous state. The more methods that are const, the faster the C++ program will run, as the compiler can allocate special sections of read-only memory for things it knows are going to be constant - this also leads to better security. The effect is snowballing - the first pass of the program on a project may, say, convert 5% of methods to const methods, but running a second pass may convert some more - as methods that call the methods that have now been made const (but came early on in the sort order) may now be able to be constified because they are now calling const methods. Leave the program running overnight on your project continuously in a loop, and when you wake up in the morning, as many methods as possible will be const!
Nice project... Just as a challange: It would be nice if your project could also emit the new SAL annotations!
See: Header Annotations http://msdn.microsoft.com/library/de...nnotations.asp
Some annotations like "__in", "__in_opt", "__out", "__out_opt" could be "easily" figured out only by looking into the source of the function...
-- Greetings Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
Hi Bonj wrote: Also interested to know what effect __opt has at compile time compared to run time, since whether a 'NULL' parameter is going to be passed surely can't always be detected at compile time?
This is a great new feature! It can be *always" detected at compile
time! The new VS2005 has a static code-analysis-tool, which can find out
all possible code-paths...
If the calling function passes a parameter which was declared as __in
(without __opt), then it checks if this parameter might become NULL (for
example if this is a passed-in parameter, then this parameter must also
be declared as _not_ __opt).
From my point, it is a great feature!
--
Greetings
Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
"Bonj" <a@b.com> wrote in message
news:eN****************@TK2MSFTNGP14.phx.gbl... the algorithm would have to be a lot more complex in order to marry these up in order to score a hit. Perhaps a compromise approach would be to develop a new strain of the program to constify parameters rather than methods, running the two alternatively on a project could eventually force more and more things down the road of const-ness?, sort of like zig-zagging up a mountain...
On the right lines I think (I haven't looked at your program yet and am just
working off the description you gave). I think Bayesian probability/dynamic
programming could help you here-- it helps reduce the number of permutations
drastically.
explain more... what's Bayesian?
"Simon Trew" <ten.enagro@werts> wrote in message
news:ul**************@TK2MSFTNGP14.phx.gbl... "Bonj" <a@b.com> wrote in message news:eN****************@TK2MSFTNGP14.phx.gbl... the algorithm would have to be a lot more complex in order to marry these up in order to score a hit. Perhaps a compromise approach would be to develop a new strain of the program to constify parameters rather than methods, running the two alternatively on a project could eventually force more and more things down the road of const-ness?, sort of like zig-zagging up a mountain...
On the right lines I think (I haven't looked at your program yet and am just working off the description you gave). I think Bayesian probability/dynamic programming could help you here-- it helps reduce the number of permutations drastically. This is a great new feature! It can be *always" detected at compile time
How? What if I pass a user-entered value in such a parameter, e.g. say from
a text-box? Would it regard that as unable to ever be NULL?
Hi Bonj wrote: This is a great new feature! It can be *always" detected at compile time
How? What if I pass a user-entered value in such a parameter, e.g. say from a text-box? Would it regard that as unable to ever be NULL?
??? The user cannot pass something into the source-code... the
source-code is static.
But nevertheless, here is a small example:
void FuncDeep(__in int *somePointer)
{
// I do *not* need to check here if the pointer is "NULL",
// because "__opt" is _not_specified.
*somePointer = 12;
}
void FuncAbove(__in __opt int *someOtherPointer)
{
FuncDeep(someOtherPointer);
// => This will generate an compile-time error,
// because it is not allowed to pass an
// possible NULL-pointer to "FuncDeep"
}
--
Greetings
Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
It's not made clear if this is only for pointers, or any type of parameter.
But what if I, say, pass the value in a textbox to a function with
parameters that aren't declared __opt?
Also, what syntactically is there to distinguish between "not using __opt"
and "not using this feature at all" - is there a compiler switch?
"Jochen Kalmbach [MVP]" <no********************@holzma.de> wrote in message
news:eJ**************@TK2MSFTNGP15.phx.gbl... Hi Bonj wrote:This is a great new feature! It can be *always" detected at compile time
How? What if I pass a user-entered value in such a parameter, e.g. say from a text-box? Would it regard that as unable to ever be NULL?
??? The user cannot pass something into the source-code... the source-code is static.
But nevertheless, here is a small example:
void FuncDeep(__in int *somePointer) { // I do *not* need to check here if the pointer is "NULL", // because "__opt" is _not_specified. *somePointer = 12; }
void FuncAbove(__in __opt int *someOtherPointer) { FuncDeep(someOtherPointer); // => This will generate an compile-time error, // because it is not allowed to pass an // possible NULL-pointer to "FuncDeep" }
-- Greetings Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
I've discovered another problem with using this, which is such a ballache
you probably wouldn't want to do it unless you got round this problem.
Namely, that it may make a method in a base class const, but not a method
that's overriden in a derived class. Hence, on an instance of a derived
class calling the function through pointer to base will call the base
class's function, giving a run-time bug.
"Bonj" <a@b.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... Modifies code files in a C++ project to make as many class member methods 'const' as possible. It parses the methods in all the files, tries making them 'const', tests whether the build succeeds and if not reverts to the previous state. The more methods that are const, the faster the C++ program will run, as the compiler can allocate special sections of read-only memory for things it knows are going to be constant - this also leads to better security. The effect is snowballing - the first pass of the program on a project may, say, convert 5% of methods to const methods, but running a second pass may convert some more - as methods that call the methods that have now been made const (but came early on in the sort order) may now be able to be constified because they are now calling const methods. Leave the program running overnight on your project continuously in a loop, and when you wake up in the morning, as many methods as possible will be const!
http://www.planetsourcecode.com/vb/s...3644&lngWId=10 Comments? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bonj |
last post by:
Modifies code files in a C++ project to make as many class member methods
'const' as possible. It parses the methods in all the files, tries making
them 'const', tests whether the build succeeds...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |