USE OF THE "SIZEOF" MACRO ON THE RISC/6000

ITEM: RTA000040288



We are finding strange results when using the "sizeof" macro with               
the xlC ( C++ ) compiler.  When defining a struct such as:                      
     struct T {          I would expect the sizeof to return 5 bytes            
       char c. 1 .;      1 for character & 4 for the integer (RISC)             
       int x;            Instead what is returned is 8 bytes.  I                
     }               assume this could be explained by the compiler             
aligning the declarations on word boundaries.  Another guy in our               
group said that it even makes a difference how the attributes are               
arranged in the structure.  That by shifting the char around different          
values for the sizeof macro are obtained.  We need to be able to                
receive the correct number of bytes that are defined in the structure.          
We use the sizeof in the size field of the memcpy function.  If                 
sizeof returns more bytes than what is declared, this messes up the             
destination field.  I was wondering if there are any compiler switches          
or something of that nature.  I also do not want to degradate the              
performance of the code ( in case the switch says to byte align ).              
I guess my question is how can I get sizeof to work with fast performance.      
                                                                                
---------- ---------- ---------- --------- ---------- ----------                
A:  As you said, the problem you encountered with the "sizeof" macro            
    is in fact due to the declarations on the word boundaries by the            
    compiler.  We re-created your program, and found a way to get the           
    specific total number of bytes in "struct T".  We accomplished this         
    by compiling the program with the "-qalign=packed" option, and              
    we obtained the desired number of bytes.  This option essentially           
    aligns every class with respect to its bytes, regardless of its             
    individual members.  For further explanations on this compiling             
    option, you may refer to INFOEXPLRER under the titles                       
                                                                                
              Alphabetical Summary List of the XL X Compiler Options           
              Detailed Descriptions of the XL C Compiler Options                
                                                                                
---------- ---------- ---------- --------- ---------- ----------                
                                                                                
                                                                                
This item was created from library item Q655175      3431N                      
                                                                                
Additional search words:                                                        
AIX ALTERNATE COMPILERS CUSTORG FEB94 INDEX IX MACRO MACROS OZNEW               
RISC RISCL RISCSYSTEM SIZEOF SOFTWARE XLC 1.1.2.34 3.2.4 3431N 6000             
                                                                                
                                                                                
                                                                                
                                                                                
                                                                               


WWQA: ITEM: RTA000040288 ITEM: RTA000040288
Dated: 06/1996 Category: RISCL
This HTML file was generated 99/06/24~12:43:15
Comments or suggestions? Contact us