This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

printing sizeof() values

I'm trying to print out sizeof() values for some of my structures. They are coming out incorrect. Here is a small table in which I've done this on different platforms:

Linux : sizeof(TChannel) = 1460
Windows: sizeof(TChannel) = 1460
8051 : sizeof(TChannel) = 1361

Are there byte-alignment issues perhaps? I have both Linux and Windows defaulting to a 1-byte boundary for byte alignment in structures. Does the 8051 default to something different?

Here's my code for the 8051:
Debugf( "sizeof(TChannel) = %u\r\n", sizeof( TChannel ) );

I've tried %u, %d, %lu, %bu, %X but can't get the right value. Here's my Debugf() function in case that might be messing things up:

void Debugf(BYTE* format, ...)
{
#ifdef DEBUG
xdata BYTE buf[64];
va_list arglist;
va_start (arglist,format);
vsprintf(buf,format,arglist);
va_end (arglist);
SendSerialData( buf, strlen( buf ) );
#endif
}

I don't think the problem is in my SendSerialData() function as that seems to work well.

Any ideas?

Parents
  • I didn't do this because I couldn't get the type 'bit' to be declared in xdata. The compiler choked (I forget the error message).

    Of course it choked, bit data is a not only an 8051 type but a memory space, that space is at DATA address 0x20 and extends for some number of bytes that can be treated as true bit types. It is a contradiction to attempt an XDATA bit var. For structs (or do you mean C bit-fields?) you must use the type unsigned char for the next most efficient access (remember, you pay a penalty for the signed versions).

Reply
  • I didn't do this because I couldn't get the type 'bit' to be declared in xdata. The compiler choked (I forget the error message).

    Of course it choked, bit data is a not only an 8051 type but a memory space, that space is at DATA address 0x20 and extends for some number of bytes that can be treated as true bit types. It is a contradiction to attempt an XDATA bit var. For structs (or do you mean C bit-fields?) you must use the type unsigned char for the next most efficient access (remember, you pay a penalty for the signed versions).

Children
No data