[ansi 89] inline

  • Thread starter Charles Harrison Caudill
  • Start date
C

Charles Harrison Caudill

Forgive the ignorance, I don't have k&r w/ me at the moment:

is there a way to do inline in ansi 89? 99?
 
R

Régis Troadec

Hi,

Charles Harrison Caudill said:
Forgive the ignorance, I don't have k&r w/ me at the moment:

is there a way to do inline in ansi 89? 99?

Yes in C99 with the inline keyword, no in C89.

Regards, Regis.
 
A

Artie Gold

Charles said:
Forgive the ignorance, I don't have k&r w/ me at the moment:

is there a way to do inline in ansi 89? 99?
C99 has `inline'. C89/90 does not.

The closest you can come to inlining in C89 is through the use of (some
often pretty ugly) macros, which you should *definitely* avoid if possible.

HTH,
--ag

[BTW - some C89 compilers offer `inline' as an extension.]
 
C

Charles Harrison Caudill

Charles Harrison Caudill said:
Forgive the ignorance, I don't have k&r w/ me at the moment:
is there a way to do inline in ansi 89? 99?

I was reading throught the GNU coding standards and I came across a good
suggestion for this problem:

#ifdef STD_C99_OR_WHATEVER
#define INLINE inline
#else
#define INLINE
#endif
 
G

Gordon Burditt

is there a way to do inline in ansi 89? 99?

In C89 it is not possible, in a standard way, to turn OFF inlining.

Gordon L. Burditt
 
D

Dan Pop

In said:
C99 has `inline'. C89/90 does not.

The closest you can come to inlining in C89 is through the use of (some
often pretty ugly) macros, which you should *definitely* avoid if possible.

Why avoid them? Function-like macros have been introduced into the
language for this very purpose.

Dan
 
D

Dan Pop

In said:
In C89 it is not possible, in a standard way, to turn OFF inlining.

It surely is: use a function pointer initialised in a different
translation unit.

Dan
 
D

Dan Pop

In said:
Well, the linker could still inline the code. Also, the code
could be inlined at runtime (in a bytecode implementation),
or even by a CPU. More info:
http://www.cuj.com/documents/s=8906/cujexp0311sutter/sutter.htm

Not if you do it right:

In the translation unit containing the definition of foo:

typedef void func(void);
func *array[5] = {foo, foo, foo, foo, bar};

In the translation unit calling foo:

typedef void func(void);
extern func *array[5];
...
array[rand() % 4]();

Show me the system smart enough to realise that this expression can be
*always* substituted by a call to foo.

Dan
 
G

Gordon Burditt

In C89 it is not possible, in a standard way, to turn OFF inlining.
Well, the linker could still inline the code. Also, the code
could be inlined at runtime (in a bytecode implementation),
or even by a CPU. More info:
http://www.cuj.com/documents/s=8906/cujexp0311sutter/sutter.htm

Not if you do it right:

In the translation unit containing the definition of foo:

typedef void func(void);
func *array[5] = {foo, foo, foo, foo, bar};

In the translation unit calling foo:

typedef void func(void);
extern func *array[5];
...
array[rand() % 4]();

Show me the system smart enough to realise that this expression can be
*always* substituted by a call to foo.

Quote me the portion of the ANSI C standard that says it's not
allowed to make such a substitution.

As a practical matter, you've turned off inlining in at least 99.99%
of implementations. Probably 100% of existing ones. As a practical
matter, no existing implementation uses 97-bit longs. Nothing in
ANSI C prohibits either.

Gordon L. Burditt
 
D

Dan Pop

In said:
In C89 it is not possible, in a standard way, to turn OFF inlining.

It surely is: use a function pointer initialised in a different
translation unit.

Well, the linker could still inline the code. Also, the code
could be inlined at runtime (in a bytecode implementation),
or even by a CPU. More info:
http://www.cuj.com/documents/s=8906/cujexp0311sutter/sutter.htm

Not if you do it right:

In the translation unit containing the definition of foo:

typedef void func(void);
func *array[5] = {foo, foo, foo, foo, bar};

In the translation unit calling foo:

typedef void func(void);
extern func *array[5];
...
array[rand() % 4]();

Show me the system smart enough to realise that this expression can be
*always* substituted by a call to foo.

Quote me the portion of the ANSI C standard that says it's not
allowed to make such a substitution.

There is nothing preventing a conforming implementation from using ESP
(extra sensorial perception) in figuring out the program's output and only
generating the code involved in the generation of that output. It makes
precious little sense to talk about what an implementation can
*theoretically* do.
As a practical matter, you've turned off inlining in at least 99.99%
of implementations. Probably 100% of existing ones.

Looks good enough to me, considering that I only used standard code,
as required in the original statement, still included at the top of the
article.

Dan
 

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

Similar Threads

Minimum Total Difficulty 0
Translater + module + tkinter 1
Border Radius is affecting Header 1
Question about makefile 5
Blue J Ciphertext Program 2
inline 3
inline 5
Box not floating next to each other 1

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top