Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c.moderated > #412
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Newsgroups | comp.lang.c.moderated |
| Subject | Re: distributing data across a structure (new to c please help) |
| Date | 2012-08-20 22:11 -0500 |
| Organization | Usenet Fact Police |
| Message-ID | <clcm-20120820-0003@plethora.net> (permalink) |
| References | <clcm-20120809-0001@plethora.net> <clcm-20120820-0001@plethora.net> |
On Mon, 2012-08-20, Dennis Yurichev wrote:
> nwdpil <mkeput@gmail.com> writes:
>
>> the ulimate goal is to read the MZ header from a binary windows pe
>> file, which is simple enough. anyway the theory goes (and this is the
>> bit i dont understand im new to c programming) i memcpy the data from
>> the file ACROSS a struct. is this possible?
...
>> typedef struct _test {
>> char b[8];
>> char bb[8];
>> }; test, *ptest;
>
> Also, do not forget about C compiler may align all struct members by 4
> bytes on x86 and 8 bytes on Win64.
> Since Windows PE file fields are all differently sized and this is very
> important, please consult "pack" pragma:
> http://msdn.microsoft.com/en-us/library/2e70t5y1(v=vs.80).aspx
Or skip the "map binary data to a struct" strategy and stick to
portable C, reading the MZ header octet by octet from an uint8_t
array. I find this much easier in the long run. For example, you
avoid endianness issues.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to comp.lang.c.moderated | Previous | Next — Previous in thread | Find similar
distributing data across a structure (new to c please help) nwdpil <mkeput@gmail.com> - 2012-08-09 20:32 -0500
Re: distributing data across a structure (new to c please help) James Kuyper <jameskuyper@verizon.net> - 2012-08-10 00:43 -0500
Re: distributing data across a structure (new to c please help) Dennis Yurichev <dennis_mailing_lists@conus.info> - 2012-08-20 14:17 -0500
Re: distributing data across a structure (new to c please help) Keith Thompson <kst-u@mib.org> - 2012-08-20 22:10 -0500
Re: distributing data across a structure (new to c please help) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-08-20 22:11 -0500
csiph-web