santosh <santosh.k83@gmail.comwrites:
Quote:
copx wrote:
>
Quote:
>Do compilers inline functions even if the programmer could not do
>it manually because the needed information is hidden at the language
>level?
>>
>I am talking about stuff like incomplete types and static variables
>e.g.
>>
>..
>get_attribute(object);
>..
>Where object is an incomplete type in this unit and get_attribute
>basically just does object->attribute.
>>
>Or
>>
>get_color(x);
>>
>which should translate into Colors[x] but Colors[] is an array
>declared static in another unit i.e. not accessible here at language
>level.
>
The compiler could inline the functions if it had access to their source
code. It cannot do so if they are in the form of libraries. Usually
code to manage opaque data is already compiled and only public
declarations are available in source form, so inlining may not be
possible.
Strictly speaking, the *compiler* can't do this kind of inlining even
if it has access to the source code. It can't know that you won't
change the source code and recompile it before linking.
For example, in a.c:
get_color(x);
and in b.c:
int get_color(int x)
{
static int Colors = { ... };
return Colors[x];
}
I can compile a.c, then completly change the implementation of
get_color() and recompile b.c, then link. If the compiler has inlined
the call in a.c, I get an inconsistent program.
This kind of fancy cross-unit inlining has to be done at the linking
phase. This might re-invoke the compiler in some cases; if so, it
does so at a time when you no longer have an opportunity to modify
anything.
--
Keith Thompson (The_Other_Keith)
kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"