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

Y

Yakov

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
 
J

jacob navia

Yakov said:
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
 
Y

Yakov

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
 
C

Chris Dollin

jacob said:
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.
 
J

jacob navia

Chris said:
(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!
 
J

jacob navia

Yakov said:
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.


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
 
K

Keith Thompson

Yakov said:
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.


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?
 
C

CBFalconer

Yakov said:
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.
 
M

Mark McIntyre

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top