Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Inlining effect on Inside/Outside class definition

velvia
Beginner
243 Views

Hi,

If you have a method and you want to give the compiler a hint that it is a good idea to inline it, you currently have 2 solutions. The first one is to define the methods when you declare your class:

class Vector {
private:
    double* data_;
    double* size_;
    double* capacity_;
public:
    double& operator[](int k) {
        return data_;
    }
    ...
}

As this method might reduce readability, another solution is to use the inline keyword and define the method out of class:

class Vector {
private:
    double* data_;
    double* size_;
    double* capacity_;
public:
    inline double& operator[](int k);
    ...
}

double& Vector::operator[](int k) {
    return data_;
}

This makes the code more readable (at least I prefer it). Reading my STL implementation, I found that they use a mix of the two. Some methods (those which I think should really be inlined) are defined in the class, and others are defined out of class with the inline keyword. The file also begins with a commented declaration of the class.

So my question is the following. Do Intel compilers are more likely to inline a member function that is declared inside the class than a member function declared out of class with the inline keyword?

0 Kudos
3 Replies
KitturGanesh
Employee
243 Views

Hi,
> So my question is the following. Do Intel compilers are more likely to inline a member function that is declared inside the class than a member function declared out of class with the inline keyword?

The answer is: No, except that sometimes developers tend to use inline keyword for the larger functions, and when a function is larger it is less likely to get inlined

_Kittur.

0 Kudos
Cardin_P_
Beginner
243 Views

Faça compiladores da Intel são mais propensos para inline uma função membro que é declarada dentro da classe do que uma função de membro declarado fora da classe com a palavra-chave inline.

0 Kudos
KitturGanesh
Employee
243 Views

HI Cardin! 
I've to find someone who can decipher your response! Thanks for the response and hopefully I should find out more on that..
_Kittur

0 Kudos
Reply