|
|
bytes packing for char type
Hi guys, =)
I am doing a little experiment, and I found that this is really
interesting, but I don't know, can anyone please tell me why is that?
I've defined a structure like this
typedef struct myA
{
char c1[5];
} mya
if I send this structure from a Linux platform to a Win32 platform, it
requires 8 bytes ( yea , some how it packes 4 bytes a unit, if c1 is 3
bytes, then it sends 4 bytes for total. It does make sense for me. )
However, If I do something like this.
typedef struct myB
{
char d1[5], d2[5]; //(they both assign the value to "abcd")
int d3 = 0;
} myb
And
typedef struct myBB
{
char d4[5]; //(assign the value to "abcd")
char d5[5]; //(assign the value to "abcd")
int d6 = 0;
} mybb
somehow, in myb the data in d2 will shift to d3 ( no more contains
zero value ), but in mybb, they all contain its only value.
pretty wried. =)
thanks for telling me the answer guys =)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
tikviva
|
7/27/2004 10:58:57 AM |
|
|
0 Replies
92 Views
(page loaded in 0.026 seconds)
Similiar Articles: PL1 CHAR limit is 32767, but I need more long string type - comp ...Hi All PL1 type CHAR's largest length is 32767, but I need define a string type which largest length is 4M bytes to store MQ messages. I trie... comp.lang.c++.moderated - page 175bytes packing for char type 0 46 (7/27/2004 10:58:57 AM) Hi guys, =) I am doing a little experiment, and I found that this is really interesting, but I don't know, can ... char(1) vs Number(1) - comp.databases.oracle.server... the first form will cause an implicit CAST of BOOL_COL to NUMBER data type to ... for char(1) since when you include the internal null indicator/length bytes both a char ... Compiler for 16bit architecture - comp.compilers.lccBut on reflection, byte pointers (char*) > > shouldn't cause any difficulty. ... (Of course, if chars are just another word sized type, there's no problem.) LSA Disk Sector Read - using int 13h ah 42 (extended read) - comp ...... here is the code: typedef unsigned char BYTE; typedef ... pragma pack(1) typedef struct disk_packet { BYTE size_pack ... all you've done is changed the target type of the ... How to port 32 bit unsigned char* to 64 bit - comp.lang.c++ ...So the type to use for unsigned char* depends on what you want to do with it. ... LPSTR to PBYTE - comp.lang.c++ (8-bit based) unsigned char byte; byte var ... portability of integral types in C++ on UNIX - comp.unix ...... integral types */ #include <stdlib.h> #include <stdio.h> #include <string.h> #define SIGNED 1 #define UNSIGNED 0 char * getMatchingType(int bytes, int signed_type ... How to write Unicode - comp.lang.java.programmer... printStream.printf( "%n" );printStream.print(( char ... that require writing characters rather than bytes.Assuming that your variable "printStream" is of type ... variant data type - comp.lang.fortranHow would one support a variant data type in modern ... I would probably pack/unpack the bits using either ... PVOID byref; CHAR cVal ... Behaviour of system calls when multibyte characters are passed ...There's no guarantee that using the wchar* as a char* will result in the same bytes ... allows pointer > formats to differ depending on the type they point to, so a char ... Byte - Wikipedia, the free encyclopediaThe byte is also defined as a data type in certain programming ... is documented as CHAR_BIT as implemented in the limits.h file. Java's primitive byte data type is always ... Additions to ANSI C and C++ - - vxWorks开发网 ...The constant 1 if type bool is defined when compiling C++ ... #pragma pack(2,2) struct s0 { char a; 1 byte at offset 0, 1 byte padding 7/19/2012 8:08:34 PM
|
|
|
|
|
|
|
|
|