what is c++ ABI?

C

Chimanrao

hi,

This is what I am trying to do:
I am writing program for a OS called Symbian, which uses the gcc
compiler.

I have the following piece of code

class MyAllocator
{
};

class MyClass
{
public:
int i,j,k,l;
MyClass() {}
};

void * operator new [](size_t sz, MyAllocator *)
{
return malloc(sz);
}

int main(int argc, char *argv[])
{
MyAllocator *pAlloc = new MyAllocator;
MyClass *pClass = new(pAlloc) MyClass[3];
}

on Symbian the value for parameter sz is is 56 while on windows its
48, why is this?
I read that this has something to C++0x ABI, not sure what it means...
any explanations?

Regards
Chimanrao
 
V

Victor Bazarov

Chimanrao said:
This is what I am trying to do:
[.. different results of 'new' on different compilers ..]
I read that this has something to C++0x ABI, not sure what it means...

ABI stands for Application Binary Interface, IIRC.
any explanations?

See [expr.new]/10. The size passed to 'new' can be greater than the
"requested" if the object is an array.

V
 
C

Chimanrao

any explanations?
See [expr.new]/10. The size passed to 'new' can be greater than the
"requested" if the object is an array.

If i remove the constructor, then new gets called with size 48. Why is
that?

Regards
Chimanrao
 
D

DJ

main(int argc, char *argv[])
{
MyAllocator *pAlloc = new MyAllocator;
MyClass *pClass = new(pAlloc) MyClass[3];
}

on Symbian the value for parameter sz is is 56 while on windows its
48, why is this?

Depending on your hardware int could be 8,16,32,64 bits long, assuming
that you not using Symbian/Win on this same device. Another is
struct/class aligement which can differ between OS and compilers.
 
V

Victor Bazarov

Chimanrao said:
any explanations?

See [expr.new]/10. The size passed to 'new' can be greater than the
"requested" if the object is an array.

If i remove the constructor, then new gets called with size 48. Why is
that?

Ask the compiler/library manufacturer. It's not specified by the
language whether the size is going to be dependent on the constructor
or what the overhead is going to be. Not specified. IOW, there is
no way to answer your "why" question, except by saying "the compiler
and/or the library designer had the need to do that".

V
 
C

Chimanrao

Chimanrao said:
any explanations?
See [expr.new]/10. The size passed to 'new' can be greater than the
"requested" if the object is an array.
If i remove the constructor, then new gets called with size 48. Why is
that?

Ask the compiler/library manufacturer. It's not specified by the
language whether the size is going to be dependent on the constructor
or what the overhead is going to be. Not specified. IOW, there is
no way to answer your "why" question, except by saying "the compiler
and/or the library designer had the need to do that".

V

Can this be related to POD, non-POD types. With the constructor its a
non-POD type, but with the constructor its a POD Type.

Visual Studio and g++ did not differentiate.

Regards
Chimanrao
 
V

Victor Bazarov

Chimanrao said:
Chimanrao said:
any explanations?
See [expr.new]/10. The size passed to 'new' can be greater than
the "requested" if the object is an array.
If i remove the constructor, then new gets called with size 48. Why
is that?

Ask the compiler/library manufacturer. It's not specified by the
language whether the size is going to be dependent on the constructor
or what the overhead is going to be. Not specified. IOW, there is
no way to answer your "why" question, except by saying "the compiler
and/or the library designer had the need to do that".

V

Can this be related to POD, non-POD types. With the constructor its a
non-POD type, but with the constructor its a POD Type.

Your guess is just as good as mine. In order to stop guessing, ask
the compiler maker.
Visual Studio and g++ did not differentiate.

No additional information detected.

V
 
J

jg

I read that this has something to C++0x ABI, not sure what it means...
any explanations?
How to layout a class is part of ABI. And the layout of a class
decides how many bytes a class will consume.

JG
 
C

Chimanrao

How to layout a class is part of ABI. And the layout of a class
decides how many bytes a class will consume.

JG

Cool, is this compiler specific or does the standard mandate this?

Regards
Chimanrao
 
J

Jim Langston

Chimanrao said:
Cool, is this compiler specific or does the standard mandate this?

It is compiler/OS specific how many bytes any given class/structure will
contain because there are varying sizes of types between compilers/OSes.
Alignment issues may also be different, as well as if they do lookup tables
for functions, etc...
 
G

Guest

Cool, is this compiler specific or does the standard mandate this?

Usually platform specific (ABI that is) the layout of members is
probably the same on the for most OSes running on the same hardware
since it is limited by the hardware.
 
I

Ian Collins

Erik said:
Usually platform specific (ABI that is) the layout of members is
probably the same on the for most OSes running on the same hardware
since it is limited by the hardware.
The ABI is very much compiler specific. One of the bug bears of C++ for
desktop application and window managers is lack of ABI compatibility
between compilers.

C programmers have it easy!
 

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
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top