Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: static inline functions - possible?

Reply
Thread Tools

Re: static inline functions - possible?

 
 
Balog Pal
Guest
Posts: n/a
 
      07-31-2009

"Stephen Howe" <sjhoweATdialDOTpipexDOTcom>
>
> Is it possible to have static inline member functions of a class?


Why not?

> I dont ever recall seeing "static" and "inline" together.


With member functions you rarely spell "inline", as just defining the
function within the class makes it inline implicitly. And you must include
the definition of functions just as the definition of the class, so
separation here brings little more pain than just doing the definitions
right at the place.

> if so, how is it done ?


The same way as the regular, just add 'inline' at front. Note, that for
member functions you do NOT say 'static', ever, at the implementation point
if it is outside the class def.



 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      07-31-2009
Balog Pal wrote:
> With member functions you rarely spell "inline", as just defining the
> function within the class makes it inline implicitly. And you must include
> the definition of functions just as the definition of the class, so
> separation here brings little more pain than just doing the definitions
> right at the place.


It's a question of style, but many people prefer separating the
declaration of a class from the implementation of its inline functions,
to keep the header tidy and clean. (After all, the class declaration
often doubles as a kind of "reference manual" to the usage of the class,
especially in the lack of better documentation, or if the documentation
is impractical to read.)

If you implement the inline function inside the class declaration,
then you can indeed skip the 'inline' keyword, ie:

//-------------------------------------------------------------
// Something.hh
//-------------------------------------------------------------
class Something
{
public:
// Implicitly inline, doesn't need the keyword:
int value() const { return something; }
};
//-------------------------------------------------------------

But if you want to separate the the declaration and the implementation
in the header, you have to specify the 'inline' keyword in the
implementation:

//-------------------------------------------------------------
// Something.hh
//-------------------------------------------------------------
class Something
{
public:
int value() const;
};

// 'inline' is required here:
inline int Something::value() const { return something; }
//-------------------------------------------------------------

As you said, it makes no difference whether the function is also
static or not. Just add the 'static' keyword in the declaration (the
implementation doesn't need it).
 
Reply With Quote
 
 
 
 
Balog Pal
Guest
Posts: n/a
 
      07-31-2009
"Juha Nieminen" <(E-Mail Removed)>
> Balog Pal wrote:
>> With member functions you rarely spell "inline", as just defining the
>> function within the class makes it inline implicitly. And you must
>> include
>> the definition of functions just as the definition of the class, so
>> separation here brings little more pain than just doing the definitions
>> right at the place.

>
> It's a question of style, but many people prefer separating the
> declaration of a class from the implementation of its inline functions,
> to keep the header tidy and clean. (After all, the class declaration
> often doubles as a kind of "reference manual" to the usage of the class,
> especially in the lack of better documentation, or if the documentation
> is impractical to read.)


Yea, and for many cases the inline implementation documents what the
function does.
Where if it wouldn't there are good chances it is not fit for inlining
anyway.

Headers are good as dox, but you're better off to use doxygen or like
system -- so directly reading becomes only task of who changes it, the rest
can read the derived html, that well separates&jons the declarations, the
code, the attached text, no matter how it is spread in the source files.

I worked with those separated inlines -- at a time made some myself, my net
conclusion is it makes things worse.



 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      07-31-2009
Balog Pal wrote:
> I worked with those separated inlines -- at a time made some myself, my net
> conclusion is it makes things worse.


Makes what worse?
 
Reply With Quote
 
Balog Pal
Guest
Posts: n/a
 
      07-31-2009

"Juha Nieminen" <(E-Mail Removed)>
> Balog Pal wrote:
>> I worked with those separated inlines -- at a time made some myself, my
>> net
>> conclusion is it makes things worse.

>
> Makes what worse?


readability, understandability, maitainance...


 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      07-31-2009
Balog Pal wrote:
> "Juha Nieminen" <(E-Mail Removed)>
>> Balog Pal wrote:
>>> I worked with those separated inlines -- at a time made some myself, my
>>> net
>>> conclusion is it makes things worse.

>> Makes what worse?

>
> readability, understandability, maitainance...


IMO the readability of a class declaration suffers if all the inline
functions are implemented inside the declaration. They tend to make the
class declaration very large (in lines of code).

If the class is very small (in number of inline member functions) and
all the inline functions are one-liners, then it's ok, but not otherwise.
 
Reply With Quote
 
Balog Pal
Guest
Posts: n/a
 
      07-31-2009

"Juha Nieminen" <(E-Mail Removed)> az alábbiakat írta a következo
hírüzenetben: w3Hcm.219$(E-Mail Removed)...
> Balog Pal wrote:
>> "Juha Nieminen" <(E-Mail Removed)>
>>> Balog Pal wrote:
>>>> I worked with those separated inlines -- at a time made some myself, my
>>>> net
>>>> conclusion is it makes things worse.
>>> Makes what worse?

>>
>> readability, understandability, maitainance...

>
> IMO the readability of a class declaration suffers if all the inline
> functions are implemented inside the declaration. They tend to make the
> class declaration very large (in lines of code).
>
> If the class is very small (in number of inline member functions) and
> all the inline functions are one-liners, then it's ok, but not otherwise.


Exactly , that is how calsses shall better look. If there is a ton of
functions, and you want the compiler inline fat functions, I'd guess the
problems will not come from organizing them in the header, and will hardly
be cured by extracting those inlines.

And classes with non-obvoius interface need doxy-like tools even more.


 
Reply With Quote
 
Gerhard Fiedler
Guest
Posts: n/a
 
      08-01-2009
Balog Pal wrote:

> "Juha Nieminen" <(E-Mail Removed)> az alábbiakat írta a következo
> hírüzenetben: w3Hcm.219$(E-Mail Removed)...
>> Balog Pal wrote:
>>> "Juha Nieminen" <(E-Mail Removed)>
>>>> Balog Pal wrote:
>>>>> I worked with those separated inlines -- at a time made some
>>>>> myself, my net conclusion is it makes things worse.
>>>> Makes what worse?
>>>
>>> readability, understandability, maitainance...

>>
>> IMO the readability of a class declaration suffers if all the inline
>> functions are implemented inside the declaration. They tend to make
>> the class declaration very large (in lines of code).
>>
>> If the class is very small (in number of inline member functions)
>> and all the inline functions are one-liners, then it's ok, but not
>> otherwise.

>
> Exactly , that is how calsses shall better look. If there is a ton
> of functions, and you want the compiler inline fat functions, I'd
> guess the problems will not come from organizing them in the header,
> and will hardly be cured by extracting those inlines.


When I have eight functions each a page long, I don't like them inside
the declaration. Rips the context apart.

Gerhard
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      08-01-2009
Gerhard Fiedler wrote:
>
> When I have eight functions each a page long, I don't like them inside
> the declaration. Rips the context apart.


When I have eight functions each a page long, I know I've done something
wrong!

--
Ian Collins
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      08-01-2009
Balog Pal wrote:
>> IMO the readability of a class declaration suffers if all the inline
>> functions are implemented inside the declaration. They tend to make the
>> class declaration very large (in lines of code).
>>
>> If the class is very small (in number of inline member functions) and
>> all the inline functions are one-liners, then it's ok, but not otherwise.

>
> Exactly , that is how calsses shall better look. If there is a ton of
> functions, and you want the compiler inline fat functions, I'd guess the
> problems will not come from organizing them in the header, and will hardly
> be cured by extracting those inlines.


I'm not talking about one-liners vs. 100-liners.

Many functions which may be desirable to be inlined because of
efficiency are often 3-5 lines long, sometimes even a bit more. Add to
this the space taken by the curly braces, plus possibly all the function
parameters not fitting one single line, and you will have short
functions taking considerable amounts of visual space.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple functions (one version being inline and other beingnon-inline) Rahul C++ 3 02-28-2008 03:28 PM
Static inline functions with static local variables Martin Wells C Programming 10 10-08-2007 03:38 PM
about extern inline and static inline Sean C++ 4 04-30-2006 03:18 PM
Tool which expands implicitly inline inline functions tthunder@gmx.de C++ 3 06-16-2005 12:54 AM
External inline functions calling internal inline functions Daniel Vallstrom C Programming 2 11-21-2003 01:57 PM



Advertisments