Do inline functions have a valid code segment

R

Ranjay

Hi Everybody,

Suppose i have a function like this
class xx{
int func();
};

main(){
xx x1;
x1.func();
}

Then func() goes into the code segment . pl correct me if i'm wrong .

However if i make it inline like this

class xx{
inline int func();
};

then c++ compiler doc says that fuc() is expanded inline where its
called at x1.func() (something very similar to macros do in c) .
ofcourse the decision to make it inline or not rests with the compiler
based on optimization modes

So if func() would be expanded at the place where its called then does
it makes sense to say that inline functions do not have data segment ??


Please let me know

My thanks in advance .

Thanks
Ranjay
 
J

Jens Theisen

Ranjay said:
Then func() goes into the code segment . pl correct me if i'm wrong .

This is platform specific terminology. The language itself isn't
concerned with segments. But on platforms I know of, yes.
So if func() would be expanded at the place where its called then does
it makes sense to say that inline functions do not have data segment ??

Did you mean code segment? If yes, then no. It will be a code segment
again, it will just be within the calling function instead of being a
function on it's own.

Jens
 
M

Michiel.Salters

Ranjay said:
Hi Everybody,

Suppose i have a function like this
class xx{
int func();
};

main(){
xx x1;
x1.func();
}

Then func() goes into the code segment . pl correct me if i'm wrong .

You're wrong. The function goes wherever the compiler thinks it should
go.
The only two requirements are 1. it can be called (by xx and friends)
and
2. when called it does the right thing.

And of course the "code segment" is not even present on all CPUs.

HTH,
Michiel Salters
 
G

Greg Comeau

Suppose i have a function like this
class xx{
int func();
};

main(){
xx x1;
x1.func();
}

Then func() goes into the code segment . pl correct me if i'm wrong .

However if i make it inline like this

class xx{
inline int func();
};

then c++ compiler doc says that fuc() is expanded inline where its
called at x1.func() (something very similar to macros do in c) .
ofcourse the decision to make it inline or not rests with the compiler
based on optimization modes

So if func() would be expanded at the place where its called then does
it makes sense to say that inline functions do not have data segment ??

I'm not sure I quite understand your question, but I'll wager a guess
at what you mean: It get put into the segement of where it is expanded --
that is is gets assumed -- whether that be a local block or function
(or elsewhere) is up to the implementation. Also, notions such as
"code segment" are platform specific so also up to the implementation.
If this is not what you mean, please reelaborate in a post.
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top