Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #7852

Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++
Date 2011-07-16 11:30 +1200
Message-ID <98c0ujFv3qU3@mid.individual.net> (permalink)
References <b6cebe9c-fb96-43b7-836e-95b85ca6f03b@q17g2000vby.googlegroups.com>

Show all headers | View raw


On 07/16/11 10:36 AM, Hetware wrote:
> I have some ancient c code that reads files stored in raw binary
> format.  The first 216 bytes are to be read into an instance of:
>
> struct Sheader
> {
> 	long	attr_start;
> 	long	form_start;
> 	short	fsize;
> 	short	attr_size;
> 	short	lastfieldidx;
> 	short 	num_inputs;
> 	char	oldheader[200];
> };
>
> The way the C code does this is by fread ((void *)header, sizeof
> (struct Sheader), 1, file);  Is there a better way to do this in C++?

Not really (but you don't need 'struct" in there), it's awful in C and 
it will still be awful in C++!

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Hetware <fjolsvit@gmail.com> - 2011-07-15 15:36 -0700
  Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Ian Collins <ian-news@hotmail.com> - 2011-07-16 11:30 +1200
    Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Hetware <fjolsvit@gmail.com> - 2011-07-15 17:23 -0700
      Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Hetware <fjolsvit@gmail.com> - 2011-07-15 17:58 -0700
      Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file);   in C++ Ian Collins <ian-news@hotmail.com> - 2011-07-16 13:18 +1200
        Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Hetware <fjolsvit@gmail.com> - 2011-07-15 18:37 -0700
        Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ gwowen <gwowen@gmail.com> - 2011-08-10 03:00 -0700
      Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Arvind <bharti.arvind@gmail.com> - 2011-07-15 20:39 -0700
      Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Nobody <nobody@nowhere.com> - 2011-07-16 13:49 +0100
      Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Todd Carnes <toddcarnes@gmail.com> - 2011-07-16 13:17 +0000
      Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Paul N <gw7rib@aol.com> - 2011-07-16 09:51 -0700
        Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Paavo Helde <myfirstname@osa.pri.ee> - 2011-07-16 12:16 -0500
  Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Paavo Helde <myfirstname@osa.pri.ee> - 2011-07-16 03:46 -0500
    Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Juha Nieminen <nospam@thanks.invalid> - 2011-07-17 13:46 +0000
      Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Robert Wessel <robertwessel2@yahoo.com> - 2011-07-17 12:51 -0500
  Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Krice <paulkp@mbnet.fi> - 2011-07-16 02:44 -0700
  Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ hanukas <jukka@liimatta.org> - 2011-07-17 11:32 -0700
    Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Hetware <fjolsvit@gmail.com> - 2011-08-01 09:18 -0700
      Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-08-01 20:17 +0000
    Re: How to fread ((void *)header, sizeof (struct Sheader), 1, file); in C++ James Kanze <james.kanze@gmail.com> - 2011-08-07 11:33 -0700

csiph-web