Kiran Divakaran wrote: > Hi All, > > I have a query with #defines in C. > > There is a -E compiler option which would expand the #define at compile time > and create an intermediate file and create the object file for the same. > > But normally do #defines get expanded at compile time or at run time. > > My feeling it gets expanded at run time and not in the object code. > > Also inline functions inline the code which means these functions will have > the code embedded in the object code. > > This is not the case for #defines which get expanded at runtime . > > Please clarify . > > > Thanks, > Kiran
Get yourself a copy of the ANSI C Standard. There is no "feeling" involved in the official technical manual on the language itself. You can simply look up whatever questions you have about how the language operates. To answer the question, #defines are preprocessor directives. The word 'preprocessor' should be the hint to you that it has to do with something that happens before the actual compilation stage. The first thing a compiler does is to run the source code through the preprocessor. After that, the resulting, expanded code is compiled. #include's and #define's are basically search-and-replace statements. The -E option loses semantic value. For instance, the compiler, despite expanding the code, will (internally) keep track of what file and line number a specific bit of code occurs on - so that, when it encounters an error, it can spit out the file and line number along with the error message. The -E option won't generally display such information. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
