Article View: comp.std.c
Article #4301REQ: Help with structs - accessing data
From: William Robert Night
Date: Sat, 28 Oct 1995 11:58
Date: Sat, 28 Oct 1995 11:58
38 lines
1789 bytes
1789 bytes
The basic idea is, read 256 bytes of data that form a packet into a
buffer. Point a struct * at it and read data out in a structured fashion.
The problem is that I can't line things up properly... my compiler
(TC++3.0 for msdos) seems to put chars in two bytes of storage.
ie... I need 35 bytes for a text string (not null terminated, just up to
35 chars padded with spaces) and JUST 35 bytes, right after that is an
offset into a file for the data described by the text string.
I tried char name[35];
But, sizeof(name) reported 36... char name[34]; sizeof(name) reported 34..
(always rounding up the the nearest multiple of two).
This means that if I try to make a struct like
struct packet {
long int data_size;
char name[35];
long int data_offset;
};
that sizeof(struct packet) reports 44 bytes rather than 43 like it should
(read, like I want it too.)
When I use this, x = packet->data_offset; I get three bytes of the
four-byte integer and one byte of something weird.
I tried to get around this by using char name[34]; and char junk; but a
single char takes up two bytes as well.
The reason I'm asking this in a C group not an MSDOS group is that I was
wondering if the ansi-C standard requires things to be aligned in a
certain way or if this is one of those things, like the size of 'int'
that is somewhat arbitrarily decided by compiler makers?
Technical Details
Message-ID:
<46t5tb$ad0@wolfe.wimsey.com>Path:
arc1-ca.pugleaf.net!in1.uu.net!van-bc!vanbc!wnightShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!van-bc!vanbc!wnight From: wnight@vanbc.wimsey.com (William Robert Night) Newsgroups: comp.std.c Subject: REQ: Help with structs - accessing data Date: 28 Oct 1995 11:58:35 GMT Organization: Wimsey Information Services Message-ID: <46t5tb$ad0@wolfe.wimsey.com> NNTP-Posting-Host: vanbc.wimsey.com X-Newsreader: TIN [version 1.2 PL2]