Results 1 to 7 of 7

Thread: Using sizeof () class with empty base class in GCC

  1. #1
    Join Date
    Mar 2011
    Posts
    88

    Using sizeof () class with empty base class in GCC

    Hey dude, before doing any risky solution I must suggest you the basic thing in this problem. The sizeof() method of the gcc will be help to get the size of the class or variable. Then I think you need to just retry this code. There might be possible that this will work and the problem is solved. The other way is to mention that both VC++ and GCC output. This will generate sizeof(Vector4) = 16 result. Then try this and see the result.

  2. #2
    Join Date
    May 2009
    Posts
    529

    Re: Using sizeof () class with empty base class in GCC

    This type of different output generate because a difference in those compilers of the system. This compiler will be generating vtables. This vtables is an virtual table and it provide the size of the class or the variable to the sizeof() class. Hence you need to check this result on the different compiler. You also check this on the different system. This will be helping to you for solving such programming problem. The C++ standard compilers will also good choice.

  3. #3
    Join Date
    Apr 2009
    Posts
    569

    Re: Using sizeof () class with empty base class in GCC

    If you clearly think this code then you observe that it happen only when both Vector4 AND Matrix4x4 inherit from Base. Does really you need inheritance in this situation. The heterogeneous Base* container of Vector4s and Matrix4x4s help to also alternatively do this task. The Object Oriented approach is generally damaging to performance in this case. The better way is using one of the open source graphics math libraries. This is help to solve the problem.

  4. #4
    Join Date
    May 2009
    Posts
    539

    Re: Using sizeof () class with empty base class in GCC

    I think you need to do some different thing in this problem. Hence use the helper functions to 'Base' class. This helper function was able to access from both the child classes. You need to remove the base class in any 'Vector4' or 'Matrix4x4' class for fixing this problem. This will be help to 'Base class' will remain empty of member variables. I hope this work and the program gives correct result. Then try this and it might work in your case.

  5. #5
    Join Date
    May 2009
    Posts
    527

    Re: Using sizeof () class with empty base class in GCC

    A programmer should in no way think what the sizeof() a type is other than sizeof(char). It is guaranteed to be 1. By default this is based on the application on sizeof(type). A compiler is free to create the sizeof() of any user-defined type. A user-defined struct or class can have padding or special alignment that would reason unusual results. Even the same compiler may be generate the different result. Then use this and it help to solve the problem.

  6. #6
    Join Date
    Apr 2009
    Posts
    488

    Re: Using sizeof () class with empty base class in GCC

    GCC C++ follows standard rules such as class EmptyBase {}; --> sizeof(EmptyBase) == 1. The other thing is to be any number of empty-bases class will plot to 0 in the struct offset. This is also unique types. Non empty-base parent’s class is declared with only padding for alignment. If the derived class first member right away follows empty-bases then it not derives. This will be help to you for solving such kind of troubles.

  7. #7
    Join Date
    May 2009
    Posts
    543

    Re: Using sizeof () class with empty base class in GCC

    Maybe you didn’t know but all empty-base classes will come out to zero effective storage in its derived class. You have not need to concern the current offset if not go after by another empty-base class. This is the main rule in the gcc sizeof () method. You need to follow this rule. This will be providing the restriction over such kind of problems. If you follow this rule then this problem are not occur in this programming.

Similar Threads

  1. Event handlers vs. base class method overrides
    By Tailapa in forum Software Development
    Replies: 5
    Last Post: 26-06-2011, 07:38 PM
  2. Compiling error C2504: Base class undefined
    By vISHaTAN in forum Software Development
    Replies: 6
    Last Post: 26-06-2011, 07:35 PM
  3. Replies: 4
    Last Post: 08-01-2011, 07:52 AM
  4. What is Visual base class in C++?
    By Venugopala in forum Software Development
    Replies: 4
    Last Post: 28-12-2010, 08:11 AM
  5. Replies: 5
    Last Post: 12-02-2010, 06:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,132,968.26326 seconds with 17 queries