Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Is the 'inline' keyword legal in declarations?
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
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
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
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Eric Hopper  
View profile  
 More options Aug 22 1998, 3:00 am
Newsgroups: comp.lang.c++.moderated
From: Eric Hopper <ehop...@globalmt.com>
Date: 1998/08/22
Subject: Is the 'inline' keyword legal in declarations?
I'm having an argument with a cow orker about whether or not
it's legal to put the inline keyword in the declaration of a global or
member function.

        For example, is:

inline void foo(int i);

inline void foo(int i)
{
   write_stuff(i);

}

        legal?  Is it recommended?

        How about:

class A {
 public:
   inline void foo(int i);

};

inline void A::foo(int i)
{
   write_stuff(i);

}

        Is that legal?  Is it recommended?

        One of the reasons this comes up is that for member variables
and functions, the 'static', and 'virtual' keywords are ONLY legal in
the declaration, and not in the definition.

        Another question has to do with optimization.  If you have a
case:

class A {
 public:
   inline int getComputedValue() const;
   inline int getValue() const;

};

inline int A::getComputedValue() const
{
   return(getValue() * 3);

}

inline int A::getValue() const
{
   return(2};

}

        If the 'inline' isn't present in the declaration of
[A::getValue() const], how does the compiler know to inline it in the
definition of [A::getComputedValue() const] without excessive
lookahead?

        If it wouldn't be too difficult, mailed (as well as posted)
responses would be appreciated.

Thanks,
--Eric Hopper

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


 
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.
Siemel Naran  
View profile  
 More options Aug 23 1998, 3:00 am
Newsgroups: comp.lang.c++.moderated
From: sbna...@fermi.ceg.uiuc.edu (Siemel Naran)
Date: 1998/08/23
Subject: Re: Is the 'inline' keyword legal in declarations?
On 22 Aug 1998 10:19:52 -0400, Eric Hopper <ehop...@globalmt.com> wrote:

>I'm having an argument with a cow orker about whether or not
>it's legal to put the inline keyword in the declaration of a global or
>member function.

It's legal.  You can put inline either in the in-class declaration,
in the in-class definition, in the outof-class definition, or in
both the in-class declaration and outof-class definition.

If I define an inline func outiside the class, I like to put the
'inline' in both places.  This tells readers of the class -- 'hey,
this is an inline func, and if it is inlined it should have no
func call overhead, but it will look kind of messy if I define it
here'.

You can use 'inline' in any function declaration.  You can even
use 'inline' in friend declarations

--
----------------------------------
Siemel B. Naran (sbna...@uiuc.edu)
----------------------------------

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


 
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.
Andrei Alexandrescu  
View profile  
 More options Aug 23 1998, 3:00 am
Newsgroups: comp.lang.c++.moderated
From: "Andrei Alexandrescu" <alexandres...@micromodeling.com>
Date: 1998/08/23
Subject: Re: Is the 'inline' keyword legal in declarations?
>I'm having an argument with a cow orker about whether or not

Interesting typo.

>it's legal to put the inline keyword in the declaration of a global or
>member function.

The inline qualifier is allowed in declarations.
To the best of my knowledge, it's also often recommended. As always,
whenever you pass more information to the compiler, it is able to do more
for you. Consider:

class A
{
    public:
    f();
    g() { return f(); }

};

inline A::f()
{
    return 0;

}

In this case certain compilers won't be able to inline g() correctly.
They will generate an out-of-line call in g() for f(). When the compiler
discovers that f() is inline, it's too late, the romance is over...

So you're right in the last part of your message. However, this is not
generally true, as the compilers may have different degrees of
intelligence built in. But if you really would die for inlining, it's
better to put the darned inline in there.

Regards,

Andrei

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


 
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.
Steve Clamage  
View profile  
 More options Aug 23 1998, 3:00 am
Newsgroups: comp.lang.c++.moderated
From: clam...@Eng.Sun.COM (Steve Clamage)
Date: 1998/08/23
Subject: Re: Is the 'inline' keyword legal in declarations?

Eric Hopper <ehop...@globalmt.com> writes:
>I'm having an argument with a cow orker about whether or not
>it's legal to put the inline keyword in the declaration of a global or
>member function.

It is always legal, except at block scope. There is little
point in doing so. See the answer to the next question.

You can't expect a function call to be generated inline if the
definition hasn't yet been seen. Move the definition of getvalue
ahead of the definition of getComputedValue.

--
Steve Clamage, stephen.clam...@sun.com

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


 
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.
markw65  
View profile  
 More options Aug 23 1998, 3:00 am
Newsgroups: comp.lang.c++.moderated
From: mark...@my-dejanews.com
Date: 1998/08/23
Subject: Re: Is the 'inline' keyword legal in declarations?
  {We encourage a "no more than 50% quoted material" guideline...
  please don't overquote. -mod}

In article <6rnfq5$lt...@engnews1.eng.sun.com>,
  clam...@Eng.Sun.COM (Steve Clamage) wrote:

I would not be very happy with a compiler which didnt inline due to
declaration order. Inlining aside, how do you do any kind of
interprocedural
optimization without reading in the whole translation unit? (Better
still the
entire program).

Mark Williams

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


 
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.
Paul Grealish  
View profile  
 More options Aug 24 1998, 3:00 am
Newsgroups: comp.lang.c++.moderated
From: Paul Grealish <paul.greal...@uk.geopak-tms.com>
Date: 1998/08/24
Subject: Re: Is the 'inline' keyword legal in declarations?

Eric Hopper wrote:

> I'm having an argument with a cow orker about whether or not
> it's legal to put the inline keyword in the declaration of a global or
> member function.

It's legal to place 'inline' before either
the definition or the declaration or both.
With regard to linkage, here's the effect
that the placement of the keyword has(*):

                      Foo.h      Foo.cpp      Linkage
                      -----      -------      -------
inline specified        0           0         External
                        0           1         Internal
                        1           0         Internal
                        1           1         Internal

(*) Using MSVC++5.0 although I'd expect other
    compilers to behave the same way.

--
+---------------------------------+
|         Paul Grealish           |
|       GEOPAK-TMS Limited        |
|       Cambridge, England        |
| paul.greal...@uk.geopak-tms.com |
+---------------------------------+

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


 
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.
Bill Wade  
View profile  
 More options Aug 24 1998, 3:00 am
Newsgroups: comp.lang.c++.moderated
From: "Bill Wade" <bill.w...@stoner.com>
Date: 1998/08/24
Subject: Re: Is the 'inline' keyword legal in declarations?

Paul Grealish wrote in message <35E15D08.1...@uk.geopak-tms.com>...
>With regard to linkage, here's the effect
>that the placement of the [inline] has(*):
> [...]
>(*) Using MSVC++5.0 although I'd expect other
>    compilers to behave the same way.

According to the standard, inline has no effect on linkage.  At one time
(ARM) it did make a difference, and compilers are not all up to date in
this
regard.  If you are working with many compilers (or any older
compilers),
then I'd recommend you be explicit about the linkage you desire (extern
or
static/unnamed-namespace).

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


 
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.
Siemel Naran  
View profile  
 More options Aug 25 1998, 3:00 am
Newsgroups: comp.lang.c++.moderated
From: sbna...@fermi.ceg.uiuc.edu (Siemel Naran)
Date: 1998/08/25
Subject: Re: Is the 'inline' keyword legal in declarations?
On 24 Aug 1998 19:14:42 -0400, Bill Wade <bill.w...@stoner.com> wrote:

>regard.  If you are working with many compilers (or any older
>compilers),
>then I'd recommend you be explicit about the linkage you desire (extern
>or
>static/unnamed-namespace).

No, 'static' for forcing internal linkage has been deprecated.  Use
only unnamed namespaces.  We had a thread about this recently.

--
----------------------------------
Siemel B. Naran (sbna...@uiuc.edu)
----------------------------------

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


 
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.
Steve Clamage  
View profile  
 More options Aug 25 1998, 3:00 am
Newsgroups: comp.lang.c++.moderated
From: clam...@Eng.Sun.COM (Steve Clamage)
Date: 1998/08/25
Subject: Re: Is the 'inline' keyword legal in declarations?

Paul Grealish <paul.greal...@uk.geopak-tms.com> writes:
>It's legal to place 'inline' before either
>the definition or the declaration or both.
>With regard to linkage, here's the effect
>that the placement of the keyword has(*):

The C++ standard says that "inline" have no effect
on function linkage. (The original rule was that "inline"
made the function "static" unless it was a member function.)

--
Steve Clamage, stephen.clam...@sun.com

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


 
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.
Eric Hopper  
View profile  
 More options Aug 25 1998, 3:00 am
Newsgroups: comp.lang.c++.moderated
From: Eric Hopper <ehop...@globalmt.com>
Date: 1998/08/25
Subject: Re: Is the 'inline' keyword legal in declarations?

Siemel Naran wrote:

> No, 'static' for forcing internal linkage has been deprecated.  Use
> only unnamed namespaces.  We had a thread about this recently.

        That supposes your compiler supports namespaces.  None of the
compilers I use support them, despite their obvious usefulness.

Have fun (if at all possible),
--Eric Hopper

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


 
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 »