CodeWarrior for Motorola DSP56800 calculates the C sizeof() operator differently than the SIZEOF operator in the linker. The C sizeof() operator returns the number of words, whereas the SIZEOF operator in the linker returns the number of bytes. So, to get the number of bytes in C, multiply the value by 2. Note that the char, signed char, and unsigned char types are all 16 bits long for the 56800, because that is the smallest data size that is handled by the DSP chip. So, the C sizeof() operator will return 1 for those types, which means 1 word or 2 bytes. The online manual states the following in the section "General Notes on C": -------- Note the following on the DSP56800 processors: C++ language is not supported. Floating-point functions (for example, sin, cos, and sqrt) are not supported. The sizeof function in C is not the same as the SIZEOF function in the linker. In C, the sizeof function returns a number of type SIZE_T, which the complier declares to be of type unsigned long int. The sizeof function in C returns the number of words, whereas the SIZEOF function in the linker returns the number of bytes. -------- You should note that the DSP56800 standard C library functions like memcpy(), strlen(), strncpy(), etc. all use the size value in words, not bytes. This is also true of the Motorola SDK library 56800-specific functions like memCopyXtoP(), memCopyPtoX(), and memCopyPtoP(). I hope this helps. Regards, Art Johnson Senior Systems Analyst PMC Prime Mover Controls Inc. 3600 Gilmore Way Burnaby, B.C., Canada V5G 4R8 Phone: 604 433-4644 FAX: 604 433-5570 Email: http://www.pmc-controls.com -----Original Message----- From: Nitin Madhukar Yewale [mailto:] Sent: Tuesday, September 03, 2002 9:34 PM To: Subject: [motoroladsp] Looking for equivalent function for "sizeof" Hi, According to the documentation of codewarrior SIZEOF -------- Definition The SIZEOF function returns the size of the given segment or section. The return value is the size in bytes. Prototype SIZEOF(segmentName | sectionName) -------- Does it mean that Codewarrior not supports sizeof operator in ANSI C? I have tried with small program typedef struct g { unsigned char t; unsigned int hk; }; main () { printf ("%d", sizeof (struct g)); } This gives 2 bytes but it should print 3 bytes. Please let me know is there any function to calculate size of structure in terms of bytes. Thanks and Regards, Nitin. _____________________________________ Note: If you do a simple "reply" with your email client, only the author of this message will receive your answer. You need to do a "reply all" if you want your answer to be distributed to the entire group. _____________________________________ About this discussion group: To Join: To Post: To Leave: Archives: http://www.yahoogroups.com/group/motoroladsp More Groups: http://www.dsprelated.com/groups.php3 ">http://docs.yahoo.com/info/terms/ |