[cfe-users] Clang Sizeof give diff value for Microsoft and Linux

2021-01-28 Thread Vivek Pandey via cfe-users
Hi Team,

We are using Clang 11 for our product that has common C++ code base for 
Windows, Linux, Macintosh, ….

We observed that sizeof operator gives different value on Windows and 
Linux/OSX, when the inheritance is from a common base class:

Example Sample:

#include 

struct Base {}; // empty class

struct Derived1 : Base {
int i;
};

struct Derived2 : Base {
Base c; // Base, occupies 1 byte, followed by padding for i
int i;
};

struct Derived3 : Base {
Derived1 c; // Derived1 is too derived from same Base class
int i;
};

int main()
{
assert(sizeof(Derived2) == 
2*sizeof(int));

assert(sizeof(Derived3) == 
3*sizeof(int));
}

  When we compile above program using Clang 11 and run it on 
windows and Linux  sizeof(Derived3) give different value.

We don’t want a work-around via making first data member of derived class of 
type different from class that also is derived from same empty base class.
Is there any flag that we can use so that it gives same result on all platform 
(Windows/Linux/OSX/Android/iOS/….)
Or another way to solve this gracefully.

Thank you!

Best Regards,
Vivek

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang Sizeof give diff value for Microsoft and Linux

2021-01-28 Thread David Blaikie via cfe-users
Clang on Windows is designed to be compatible with MSVC - which has
different layout requirements than the Itanium ABI/GCC on Linux. I don't
think there's a way to use the same ABI on both platforms - especially not
if you are interacting with any code compiled by another compiler on both
platforms (existing/foregin C++ precompiled libraries).

On Thu, Jan 28, 2021 at 1:45 PM Vivek Pandey via cfe-users <
cfe-users@lists.llvm.org> wrote:

> Hi Team,
>
>
>
> We are using Clang 11 for our product that has common C++ code base for
> Windows, Linux, Macintosh, ….
>
>
>
> We observed that sizeof operator gives different value on Windows and
> Linux/OSX, when the inheritance is from a common base class:
>
>
>
> Example Sample:
>
>
>
> #include 
>
>
>
> struct Base {}; // empty class
>
>
>
> struct Derived1 : Base {
>
> int i;
>
> };
>
>
>
> struct Derived2 : Base {
>
> Base c; // Base, occupies 1 byte, followed by padding for i
>
> int i;
>
> };
>
>
>
> struct Derived3 : Base {
>
> Derived1 c; // Derived1 is too derived from same Base class
>
> int i;
>
> };
>
>
>
> int main()
>
> {
>
> assert (sizeof(Derived2)
> == 2*sizeof(int));
>
>
>
> assert (
> sizeof(Derived3) == 3*sizeof(int));
>
> }
>
>
>
>   When we compile above program using Clang 11 and run it on
> windows and Linux  sizeof(Derived3) give different value.
>
>
>
> We don’t want a work-around via making first data member of derived class
> of type different from class that also is derived from same empty base
> class.
>
> Is there any flag that we can use so that it gives same result on all
> platform (Windows/Linux/OSX/Android/iOS/….)
>
> Or another way to solve this gracefully.
>
>
>
> Thank you!
>
>
>
> Best Regards,
>
> Vivek
>
>
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users