wales@ucla-cs.ARPA (Rich Wales) (03/28/86)
If a function is declared "inline" in C++, does/should this mean that the function is implicitly "static" (i.e., known only within the source file in which it appears)? Although section 8.1 of the C++ Reference Manual (in the Stroustrup book, p. 266) says that "inline" is "only a hint to the compiler, does not affect the meaning of a program, and may be ignored", consider that an "inline" function is going to have to be available at compile time if the compiler is to be able to do an inline expansion. One would therefore infer that the definition of an "inline" function must appear in each source file that invokes it (possibly via a header file; indeed, p. 107 of the book says that inline function definitions are indeed reasonable things to put in header files). If "inline" functions were not implicitly "static", though, defining one in multiple source files (via a header file, for instance) would lead to multiple external definitions of the function, with resulting linker errors. So, it seems that "inline" functions must be treated as being "static" -- though I am unable to find anything in the book that states this in so many words. I have not yet started to play with the C++ translator, by the way (though we do have it here at UCLA); I have so far been going only on the basis of the language description in the book. Also, my apologies if this topic has already been discussed; I started reading this newsgroup only a short while ago. -- Rich Wales // UCLA Computer Science Department // +1 213-825-5683 3531 Boelter Hall // Los Angeles, California 90024 // USA wales@LOCUS.UCLA.EDU ...!(ucbvax,ihnp4)!ucla-cs!wales
ark@alice.UucP (Andrew Koenig) (03/30/86)
> If a function is declared "inline" in C++, does/should this mean that > the function is implicitly "static" (i.e., known only within the source > file in which it appears)? Nope. If you don't make it static as well, the compiler must generate conventional code for it as well as any inline expansions it does, in case it's called from another file.