On Sunday 30 September 2001 00:50, Joe Smith wrote:
[...]
> > Example:
> >
> > /*
> >  * Writes "val" in big endian format into 'buf'.
> >  * Returns number of bytes written.
> >  */
> > int write_int(char *buf, int val)
> > {
> >     buf[0] = val & 0xff;
> >     buf[1] = (val>>8) & 0xff;
> >     buf[2] = (val>>16) & 0xff;
> >     buf[3] = (val>>24) & 0xff;
> >     return 4;
> > }
> >
> > Note that for total portability, your should verify that sizeof(int)
> > really is 4, as it might be smaller on some systems... (It's not a
> > problem if it's bigger - this code will still write a 32 bit int.)
>
> Is there really a situation where simple read/write of int's wouldn't
> work?
>
> Read/write do byte copies, so there's no problem with alignment in the
> FIFO buffer, and the program variables are declared 'int', so they'll
> be aligned. Both ends of an RT-FIFO are always going to be accessed by
> the same hardware arch (if not the same CPU), so whatever int size and
> byte order is used on the RT side will be correct for the user side,
> right?
>
> My code depends on this (and structs that contain only int members), so
> I'd really like to know if I've overlooked something.

No, you should be safe - the example is meant to be *totaly* safe, even 
in networked environments and the like, where you can have different 
endian CPUs. Of course, you don't have to worry about endian, floating 
point format and that kind of stuff if you're using only one kind of CPU.


//David Olofson --- Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
|      Multimedia Application Integration Architecture      |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`-------------------------------------> http://olofson.net -'
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/

Reply via email to