|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
information hiding vs. inlining
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. 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. |
|
#2
|
|||
|
|||
|
information hiding vs. inlining
copx wrote:
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. > > 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. |
|
#3
|
|||
|
|||
|
information hiding vs. inlining
santosh wrote: copx wrote: > Do compilers inline functions even if the programmer could not do it manually because the needed information is hidden at the 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. There are some compiler/linkers that make automated inline choices at link time that only need library objects. Most of the compilers that do full code optimization at link time have the ability to also inline library or application function objects without sources. Walter |
|
#4
|
|||
|
|||
|
information hiding vs. inlining
copx wrote:
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. > > 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. Some implementations are capable of doing that; it is allowed under the "as if" rule. However, being able to inline (or do any other sort of optimization) across translation units (i.e. object files) is still in its infancy and not available with most implementations. If you want your accessor functions to be inlined with common systems today, you will need to provide a complete type and static inline accessor functions in your header file. Examine, for instance, your system's <stdio.hfor ideas on how to do this. Note that using that strategy may cause significant versioning problems for you if you use <T>dynamic libraries</Tand aren't extremely careful. S |
![]() |
| Viewing: Web Development Archives > FAQs > C/C++ > information hiding vs. inlining |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|