By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,145 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,145 IT Pros & Developers. It's quick & easy.

tool that performed inlining of function bodies of which do not appear in the .h file.

P: n/a
I'd like a tool that performed inlining of function bodies of which do
not appear in the .h file.
Really.
gcc on Linux.

Yakov

Jun 26 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Yakov wrote:
I'd like a tool that performed inlining of function bodies of which do
not appear in the .h file.
You want to inline all functions that do not appear in the .h???

suppose:

inline int fn(int a)
{
if (a == 5998)
return 59;
else if (a >= 55)
return 23;
else {
while (a < 52)
a = a*a;
goto followup;
}
followup:
return a;
}
Now, you have:
int a;

....

fn(a);
fn(a+78);

You have to replace the "returns" in the function body to some generated
label.
Then, you have to replace all variables by local variables
Then, you have to replace all label names with some generated labels
so that the labels do not collide.

It looks like a lot of work for such a tool isn't it?

jacob
Jun 26 '07 #2

P: n/a
On Jun 26, 1:21 am, jacob navia <j...@jacob.remcomp.frwrote:
Yakov wrote:
I'd like a tool that performed inlining of function bodies of which do
not appear in the .h file.

You want to inline all functions that do not appear in the .h???
I did not say "all functions". Inlining must be smart.I started to use
gcc's 'static inline' trick to put function bodies into .h files (and
yes, gcc knows to do inlining -- but practically , you need to put
function body into .h file).

I find it inconvenient to put function bodies into .h files.
It looks like a lot of work for such a tool isn't it?
gcc already does it, what you describe as "lot of work.
My problem is, I want inlinking *AND* keeping
function bodies in the .c files.

Yakov
Jun 26 '07 #3

P: n/a
jacob navia wrote:
Yakov wrote:
>I'd like a tool that performed inlining of function bodies of which do
not appear in the .h file.

You want to inline all functions that do not appear in the .h???

suppose:

inline int fn(int a)
{
if (a == 5998)
return 59;
else if (a >= 55)
return 23;
else {
while (a < 52)
a = a*a;
goto followup;
}
followup:
return a;
}
Now, you have:
int a;

...

fn(a);
fn(a+78);

You have to replace the "returns" in the function body to some generated
label.
Then, you have to replace all variables by local variables
Then, you have to replace all label names with some generated labels
so that the labels do not collide.

It looks like a lot of work for such a tool isn't it?
(fx:shrug) A tool has to do whatever it has to do to provide the service
it's advertised as providing. It doesn't have to be /easy/.

A better difficulty example is a recursive function that isn't tail-
recursive.

--
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Jun 26 '07 #4

P: n/a
Chris Dollin wrote:
jacob navia wrote:
>Yakov wrote:
>>I'd like a tool that performed inlining of function bodies of which do
not appear in the .h file.
You want to inline all functions that do not appear in the .h???

suppose:

inline int fn(int a)
{
if (a == 5998)
return 59;
else if (a >= 55)
return 23;
else {
while (a < 52)
a = a*a;
goto followup;
}
followup:
return a;
}
Now, you have:
int a;

...

fn(a);
fn(a+78);

You have to replace the "returns" in the function body to some generated
label.
Then, you have to replace all variables by local variables
Then, you have to replace all label names with some generated labels
so that the labels do not collide.

It looks like a lot of work for such a tool isn't it?

(fx:shrug) A tool has to do whatever it has to do to provide the service
it's advertised as providing. It doesn't have to be /easy/.

A better difficulty example is a recursive function that isn't tail-
recursive.
And MANY others. I have still not completely finished this part in
lcc-win32...
There is (for instance) the problem that all static variables
within an inline function should point to the same storage,
and a long ETC!

Not to mention the parsing of C, the preprocessor, etc.

That tool can be only one thing:

A COMPILER!
Jun 26 '07 #5

P: n/a
Yakov wrote:
On Jun 26, 1:21 am, jacob navia <j...@jacob.remcomp.frwrote:
>Yakov wrote:
>>I'd like a tool that performed inlining of function bodies of which do
not appear in the .h file.
You want to inline all functions that do not appear in the .h???
I did not say "all functions". Inlining must be smart.I started to use
gcc's 'static inline' trick to put function bodies into .h files (and
yes, gcc knows to do inlining -- but practically , you need to put
function body into .h file).

I find it inconvenient to put function bodies into .h files.
>It looks like a lot of work for such a tool isn't it?

gcc already does it, what you describe as "lot of work.
Excuse me but you think that gcc wasn't a lot of work to write???

Or you mean that if gcc does clever optimization "XYZ"
it is NOT a lot of work to reproduce that???

Your logic is completely weird.
My problem is, I want inlinking *AND* keeping
function bodies in the .c files.
In your .h file write:

#include "inlines1.c"

and be done with it!

jacob
Jun 26 '07 #6

P: n/a
Yakov <il*****@gmail.comwrites:
On Jun 26, 1:21 am, jacob navia <j...@jacob.remcomp.frwrote:
>Yakov wrote:
I'd like a tool that performed inlining of function bodies of which do
not appear in the .h file.

You want to inline all functions that do not appear in the .h???
I did not say "all functions". Inlining must be smart.I started to use
gcc's 'static inline' trick to put function bodies into .h files (and
yes, gcc knows to do inlining -- but practically , you need to put
function body into .h file).

I find it inconvenient to put function bodies into .h files.
>It looks like a lot of work for such a tool isn't it?

gcc already does it, what you describe as "lot of work.
My problem is, I want inlinking *AND* keeping
function bodies in the .c files.
gcc implements inline functions, but it doesn't do so by transforming
the C source, which I *think* is what you're looking for.

Actually, can you be more specific about what you want? The simplest
way to inline a C function is to add an "inline" keyword to its
definition (assuming you have a compiler that supports that).

Stepping back a bit, are you sure that inlining these functions is
going to be worthwhile? Is your program not fast enough as it is?
Have you measured it?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 26 '07 #7

P: n/a
Yakov wrote:
>
I'd like a tool that performed inlining of function bodies of
which do not appear in the .h file. Really. gcc on Linux.
Use static inline descriptors, and std=C99.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 26 '07 #8

P: n/a
On Tue, 26 Jun 2007 12:11:42 -0000, in comp.lang.c , Yakov
<il*****@gmail.comwrote:
>I'd like a tool that performed inlining of function bodies of which do
not appear in the .h file.
You're wasting your time. The compiler optimiser will already be able
to do this for any function that can be appropriately optimised. If it
can't be optimised, and the "inline" hint will tell the compiler to
try, then you are unlikely to do better.
>Really.
Its also a /lot/ of work.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 26 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.