RE: [Dev-C++] Use of const qualifier
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Scott W. <se...@al...> - 2002-11-01 18:37:37
|
Thanks for the reply--very helpful. You might know the answer to a related question. . . I have a math-intensive subroutine that is called millions of times (yes, millions) by a numerical algorithm. Currently, all of the variables in this subroutine are of automatic extent. Would there be any efficiency gained by instead giving them static extent? Each call to the subroutine is independent so retaining values across calls is not an issue. Rather, this is a question of how the memory access itself is handled. Thanks. Scott -----Original Message----- From: Abhijit Shylanath [mailto:mu...@gm...] Sent: Thursday, October 31, 2002 5:30 PM To: se...@al...; Dev-C++ Mailing List Subject: Re: [Dev-C++] Use of const qualifier > where myfunc uses the values of x and the array members of y but doesn't > change them. Is there then an efficiency (speed) to be gained by instead > declaring: > > double myfunc(const double x, const double *y)? More than speed, the const qualifier is for debugging. It prevents the programmer from inadvertently changing the values of certain variables. Some new optimizing compilers also use it to align memory more efficiently. ___________________________________________________________ Abhijit Shylanath E-mail: mu...@gm... || ibr...@bi... Web-site: http://mudeth.tripod.com/ |