Is "inline" valid C?

  • Thread starter Christian Staudenmayer
  • Start date
C

Christian Staudenmayer

Hi,

is there any revision of the C standard that allows the "inline" keyword
(or a similar feature)? I know it is possible in gcc, but then it might
be a gcc feature only.

Greetings, Chris
 
D

Dave Vandervies

Hi,

is there any revision of the C standard that allows the "inline" keyword
(or a similar feature)? I know it is possible in gcc, but then it might
be a gcc feature only.

It's in C99, and also widely implemented as an extension.

If you don't use "inline" as an identifier, you can make its use in a
declaration valid-and-ignored on implementations that don't have it by
simply #defining it to nothing:

#ifndef HAS_INLINE
#define inline /*Nothing to see here, move along*/
#endif


dave
 
B

Ben Pfaff

It's in C99, and also widely implemented as an extension.

However, the semantics implemented by GCC, and presumably by
some other compilers, differ from those specified by C99.
 
C

Christian Staudenmayer

Dave said:
It's in C99, and also widely implemented as an extension.

If you don't use "inline" as an identifier, you can make its use in a
declaration valid-and-ignored on implementations that don't have it by
simply #defining it to nothing:

#ifndef HAS_INLINE
#define inline /*Nothing to see here, move along*/
#endif


dave

I think I have a misunderstanding of gcc's command line options, because
-ansi yielded an error regarding "inline". But apparently -ansi means
the same as -std=c89 (i.e. C90).

So, if I use -std=c99 I can use "inline" and still be sure that the
compiler will warn me of any violations of the standard?

Greetings, Chris.
 
M

Michael Mair

Christian said:
I think I have a misunderstanding of gcc's command line options, because
-ansi yielded an error regarding "inline". But apparently -ansi means
the same as -std=c89 (i.e. C90).

So, if I use -std=c99 I can use "inline" and still be sure that the
compiler will warn me of any violations of the standard?

If you use -std=c99 -pedantic, it should do so.
However, the C99 status page (gcc.gnu.org/c99status.html) admits that
this is still not guaranteed. OTOH, even -ansi -pedantic does not grant
that gcc will do the right thing for standard conforming C89 programs.


Cheers
Michael
 
C

Chris Croughton

If you use -std=c99 -pedantic, it should do so.
However, the C99 status page (gcc.gnu.org/c99status.html) admits that
this is still not guaranteed. OTOH, even -ansi -pedantic does not grant
that gcc will do the right thing for standard conforming C89 programs.

Does any compiler "do the right thing" with either of the standards? If
so, which (preferably a free one which runs on any platform)? All the
compilers I've ever used either don't reach the standard or they have
nonstandard extensions (in particular, I've never seen a library which
supports all of the C99 functions correctly).

Chris C
 
C

CBFalconer

Chris said:
Does any compiler "do the right thing" with either of the standards?
If so, which (preferably a free one which runs on any platform)?
All the compilers I've ever used either don't reach the standard or
they have nonstandard extensions (in particular, I've never seen a
library which supports all of the C99 functions correctly).

While I am sure that faults can be found with "gcc -ansi -pedantic"
operation, I have yet to run into them. AFAICT it suppresses all
the gnu extensions. Libraries are a separate matter, and you
should probably report any library failings. The only C99 library
known to me is from Gimpel.
 
D

Dave Vandervies

While I am sure that faults can be found with "gcc -ansi -pedantic"
operation, I have yet to run into them. AFAICT it suppresses all
the gnu extensions. Libraries are a separate matter, and you
should probably report any library failings. The only C99 library
known to me is from Gimpel.

Dinkumware also has one, don't they?

Most compilers will do C90, modulo bugs, if you can figure out how to
ask them to. A lot are making serious efforts at C99, but I don't have
up-to-date knowledge on which ones are how close. Comeau was, I believe,
the first to advertise complete compliance (on the language side only,
but it plays nicely with the Dinkumware library to get a complete
implementation); I'm not sure if it's been joined by others yet.


dave
 
E

E. Robert Tisdale

Dave said:
Comeau was, I believe, the first to advertise complete compliance
(on the language side only, but it plays nicely with the Dinkumware library
to get a complete implementation);

Comeau

http://www.comeaucomputing.com/

doesn't actually claim full compliance with ANSI/ISO standards.

"This combination of Comeau and Dinkumware
is as close as you can get to full compliance
with Standard C++ from 2003 or 1998,
Standard C from 1999 (aka C99) and
Standard C from 1990 (aka C90)."
 
M

Michael Mair

I do not know that.

If I knew one, I would gladly advertise it :)
The Dinkumware library claims C99 compliance.


Well, the things I ran into are mainly related to the problem that
typecasting to a certain floating point type does not work on x86
architectures because the gcc people rather accept excess precision
plus fast execution than the right precision plus slow execution...
There are some algorithms which do not work as expected when
you have excess precision for some expressions but not for others.
The thing I am unhappy about is that they do not document this
where everyone finds it. A mention along with the -std=... option
would suffice.

Dinkumware also has one, don't they?
Yep.

Most compilers will do C90, modulo bugs, if you can figure out how to
ask them to. A lot are making serious efforts at C99, but I don't have
up-to-date knowledge on which ones are how close. Comeau was, I believe,
the first to advertise complete compliance (on the language side only,
but it plays nicely with the Dinkumware library to get a complete
implementation); I'm not sure if it's been joined by others yet.

AFAIK, Comeau plus Dinkumware libraries is still the only compliant
combination.
 
M

Michael Wojcik

AFAIK, Comeau plus Dinkumware libraries is still the only compliant
combination.

I recently discovered that HP appears to claim its current Compaq C
implementation for OpenVMS for Alpha (only) is C99-compliant.[1]

I'm sure that's a great comfort to the hordes of Alpha OpenVMS users
out there, as HP gradually starves all of the former-Digital, former-
Compaq platforms to death.

Why HP can't provide a C99-compliant implementation for, say, HP-UX
is a mystery. The version we're using right now doesn't even have a
conforming snprintf. (Ditto the one for Tru64, another orphan HP has
kicked out into the cold.)

And to drag another recent thread back in: we were recently discussing
pre-ISO code that was still in use. Much of our C source has nasty
conditional-compilation sections that substitute K&R function
definitions for ISO ones. I was looking to get rid of those and
discovered that we're still contractually obligated to support a few
pre-standard implementations - 14 years after the first ISO standard.
(Apparently whatever implementation we're using for SINIX is one; for
all I know Fujitsu-Siemens now has a conforming implementation avail-
able for it, but switching implementations on a maintenance-only
platform is probably not a good idea.)


1. <http://h71000.www7.hp.com/commercial/c/docs/5492p001.html>; look
for "Strict C99".

--
Michael Wojcik (e-mail address removed)

Pocket #9: A complete "artificial glen" with rocks, and artificial moon,
and forester's station. Excellent for achieving the effect of the
sublime without going out-of-doors. -- Joe Green
 

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

No members online now.

Forum statistics

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

Latest Threads

Top