C/C++
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs C/C++

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old July 5th, 2008, 09:00 AM
copx
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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.




Reply With Quote
  #2  
Old July 5th, 2008, 12:00 PM
santosh
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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.


Reply With Quote
  #3  
Old July 5th, 2008, 12:39 PM
Walter Banks
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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




Reply With Quote
  #4  
Old July 6th, 2008, 12:19 PM
Stephen Sprunk
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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

Reply With Quote
Reply

Viewing: Web Development Archives FAQs C/C++ > information hiding vs. inlining


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway