Subj : Re: A really stupid Question - how to build a library To : borland.public.cpp.borlandcpp From : Ed Mulroy [TeamB] Date : Thu Oct 07 2004 09:18 am Note that I assumed from your message that you were creating code for use by students. Upon re-reading the message I am not sure how I formed that opinion. I have made more than a few bucks teaching professors C++ and C who were assigned to teach language classes but were only a few pages ahead (sometimes behind!) the students and wanted to express caution about some things. > Machines are fast. The interrupt rate is 16K ... You appear to have that issue well in hand. > ... I now have to go read about #pragma, > post and pre increment/decrement, > figure out how to use decrement given > that my mind set is to make the > variable change after the fact rather than before...., etc. #pragma : This is a method for giving the compiler a command, analagous to a command line option but in the code. For example: #pragma startup function1 will cause function1 to be added to the list of functions to be called in the startup/initialization process prior to when main is called. As shown it would be called after all the default initialization is completed. #pragma exit function1 does the same except at the end, with function1 being called prior to any of the compiler's ending/cleanup functions. Post and pre increment/decrement: ++var Increment var. The value used in the expression is the new value. var++ Increment var and save the value, but use the original value of var in the expression. Same comments and syntax with -- except that it decrements instead of incrementing. Consider the differences between what the loops do in this code: int var; for (var = 6; var < 22; var++) function_A(); for (var = 6; var < 22; ++var) function_A(); The logical operations caused by these loops differ in that the first loop requires that a copy of the original value of 'var' must be formed, saved somewhere and loaded again after the increment and store of the new value. Restating: There is some additional overhead associated with the post increment (the var++). Compiler writers have long since caught on to this common bad habit of programmers and optimize this specific usage for integers, but the syntax is the same if 'var' is an object other than an integral type. When 'var' is a class or structure, not a uncommon situation in C++, post-increment forces construction of a temporary instance of the class to capture the original state, save of the temporary somewhere (possibly causing an allocation call), call the post increment function, restore the temporary test and test, save the test results, possibly a de-allocation call for the temporary - BIG overhead. Using var++ instead of ++var is not a good habit. .. Ed > dkat wrote in message > news:4164b548@newsgroups.borland.com... > > ... we are a science research lab that knows just enough > about programming to get by (no one is going to see our > code other than us). The all caps is from Unix days - > maybe fortran - can't remember... where all caps were used > for #define which is how we used to do constants (aren't > you proud of me that I now use const rather than #define > for my Constants :) ).... But I do want to learn what I can > and very much appreciate your effort to educate. > I now have to go read about #pragma, post and pre > increment/decrement, figure out how to use decrement given > that my mind set is to make the variable change after the > fact rather than before...., etc. > > Thank you again. .