Google Groups Home
Help | Sign in
information hiding vs. inlining
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
copx  
View profile
 More options Jul 5, 9:42 am
Newsgroups: comp.lang.c
From: "copx" <c...@gazeta.pl>
Date: Sat, 5 Jul 2008 15:42:42 +0200
Local: Sat, Jul 5 2008 9:42 am
Subject: 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.

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.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
santosh  
View profile
 More options Jul 5, 11:35 am
Newsgroups: comp.lang.c
From: santosh <santosh....@gmail.com>
Date: Sat, 05 Jul 2008 21:05:05 +0530
Local: Sat, Jul 5 2008 11:35 am
Subject: Re: information hiding vs. inlining

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 to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Walter Banks  
View profile
 More options Jul 5, 1:25 pm
Newsgroups: comp.lang.c
From: Walter Banks <wal...@bytecraft.com>
Date: Sat, 05 Jul 2008 13:25:49 -0400
Local: Sat, Jul 5 2008 1:25 pm
Subject: Re: 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 to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Thompson  
View profile
 More options Jul 5, 3:47 pm
Newsgroups: comp.lang.c
From: Keith Thompson <ks...@mib.org>
Date: Sat, 05 Jul 2008 12:47:51 -0700
Local: Sat, Jul 5 2008 3:47 pm
Subject: Re: information hiding vs. inlining

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) ks...@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"


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
copx  
View profile
 More options Jul 5, 6:34 pm
Newsgroups: comp.lang.c
From: "copx" <c...@gazeta.pl>
Date: Sun, 6 Jul 2008 00:34:30 +0200
Local: Sat, Jul 5 2008 6:34 pm
Subject: Re: information hiding vs. inlining

"copx" <c...@gazeta.pl> schrieb im Newsbeitrag news:g4ntom$975$1@inews.gazeta.pl...

> Do compilers inline functions even if the programmer could not do
> it manually because the needed information is hidden at the language level?

[snip]

Thanks everyone!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen Sprunk  
View profile
 More options Jul 6, 12:31 pm
Newsgroups: comp.lang.c
From: Stephen Sprunk <step...@sprunk.org>
Date: Sun, 06 Jul 2008 11:31:09 -0500
Local: Sun, Jul 6 2008 12:31 pm
Subject: Re: information hiding vs. inlining

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.h> for ideas
on how to do this.

Note that using that strategy may cause significant versioning problems
for you if you use <OT>dynamic libraries</OT> and aren't extremely careful.

S


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google