C question - headers in mmaped files

Jepri jepri at webone.com.au
Tue Apr 1 21:52:33 EST 2003


On 2003.04.01 21:45, Duncan Roe wrote:
> dat = (data *) map+64;
> 
> means
> 
> dat = ((data*)map) + 64;
> 
> i.e. add 64 * sizeof map to machine address.
> 
> If you want dat to start 64 bytes in from map, try
> 
> dat=(data*)((char*)map+64); /* N.b. avoid confusing whitespace ;) */
> 
> Cheers ... Duncan.

Thanks to both Duncan and Martin for the tip.


and Martin:  *study* C?  That's an odd thought somehow.  I only do it 
for the fun, and somehow studying would take most of the fun out of it.
> 
> On Tue, Apr 01, 2003 at 08:53:17PM +1000, Jepri wrote:
> > Hey all, I've got a C question for them who do that sort of thing.
> Not
> > quite linux, but the list is a tad slow thesedays.
> >
> > I'm writing some code that writes and reads data out of files using
> > mmap, and I get to make up my own file format.  It seemed natural to
> 
> > have a header describing the file, but I can't figure out how to
> access
> > the header in the mmaped chunk of memory.  I thought I could just
> take
> > pointers to anywhere inside the mmaped memory and cast them to
> whatever
> > I wanted, but it doesn't seem to work for me.
> >
> > i.e. I tried something really naive like:
> >
> > map = (char *) mmap(etc etc)
> > head = (header *) map;
> > dat = (data *) map+64;
> >
> > but data ended up pointing over 1kb heigher than it should have.
> > What's the right way to do this?  Is there an easy way for me to
> make
> > multiple 'segments' in the file that have different data formats?
> >
> >
> >
> >
> 
> 


More information about the linux mailing list