RE: [Dev-C++] Use of const qualifier
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-11-02 20:28:23
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Per Westermark > Sent: Saturday, November 02, 2002 12:27 PM > To: Abhijit Shylanath > Cc: 'Dev-C++ Mailing List' > Subject: Re: [Dev-C++] Use of const qualifier > > > 1 - Declaring a function inline doesn't work for function pointers, > or when writing mixed-language programss. Usually yes. There is no rule however. For this reason, in C++ it is better to pass a type argument with static member functions. Or use function objects. > 2 - Eliminating the function to remove the function call > obviously doesn't > work either for same reason as above. > > 3 - The link referenced below is written with DSP processors > in mind. Some > optimization work. A lot of the suggestions are questionable on a > general-purpose processor. I am very busy these last days so i have no much time to post messages on the list. Regarding efficiency & C++, the best thing one can do is to use the high level constructs and do not bother about low level details. So for example use strings and pass them by reference and do not bother for the details. Regarding C, the compiler can perform whatever optimisations it likes. As a general rule one must try to avoid repeative function calls (like calling the same function 1 million times). Regarding variables with exception of large struct types, the time cost of creating and destroying variables in nowadays machine can be ignored. For a large struct, using a static struct variable can help. Again, one must think of run time optimisations when he sees that his code is unacceptable slow. Like for(size_t i=0; i<strlen(s); i++) /* ... */ If the compiler is clever, it may avoid calling strlen(), strlen(s) times. If we see that the code crawls (and only then), one can think of optimisations like: const size_t SLENGTH=strlen(s); for(size_t i=0; i<SLENGTH; i++) /* ... */ In general, do not think of optimising something without having a problem with it. Also usually run-time optimisation adds space cost, and space optimisation adds runtime cost. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |