Topic: proposed reserved words MSB, LSB, and PACKED


Author: woodstock!samchris@mcnc.org (Sam Christie P200)
Date: 21 Apr 92 13:47:29 GMT
Raw View
I am by no means a language expert, but I have often pondered the need
for language support of protocol development.  No doubt many C and C++
programmers have encountered the need to communicate between intel and
other machines.  I could delve into the problem further, but I am sure
this audience understands.  What I have always wanted is the ability to
specify the byte order of integers in a structure to be used in a message.

Consider the declaration:

class packed msb messageData {
  public:
    messageData();
    ~messageData();

  private:
    int   length;
    short someData;
    char  someOtherData;
    int   lastDataItem;
};

Ideally, given the optional keywords packed and not more than of
msb or  lsb.  Where:
   packed means don't optimize the structure for access speed.  Pack
      together the data into the minimum space.  On some machines,
      this may make the compiler output a bit more lengthy in order
      to access the data in question.
   msb means Most Significant Byte order, "BigEndian" or Motorola
      integer format.  I realize that a compiler for a littleEndian
      processor would have to jump through hoops to make this work.
   lsb means Least Signifigant byte order, "LittleEndian", or Intel
      integer format.  Obviously, bigEndian machies will have to
      do the work here.

The purpose, in case it is not immediately clear, is to permit one
source module to provide the same interface on all machine types.  Of
course I could always program in ASN.1, but I would much rather not :)

What do you folks think ?  If I am crazy, please educate me via email;
otherwise, I am interested in the ensuing discussion.

Sam Christie
BNR, Inc       Remember: I work for them, not the other way around
919/991-7244

Return mail should be addressed to:

woodstock!samchris@mcnc.org




Author: nevries@accucx.cc.ruu.nl (Nico de Vries.)
Date: 21 Apr 92 20:04:16 GMT
Raw View
In <13251@bwdls58.bnr.ca> woodstock!samchris@mcnc.org (Sam Christie P200) writes:

>...
>Ideally, given the optional keywords packed and not more than of
>msb or  lsb.  Where:
>   packed means don't optimize the structure for access speed.  Pack
>      together the data into the minimum space.  On some machines,
>      this may make the compiler output a bit more lengthy in order
>      to access the data in question.
>   msb means Most Significant Byte order, "BigEndian" or Motorola
>      integer format.  I realize that a compiler for a littleEndian
>      processor would have to jump through hoops to make this work.
>   lsb means Least Signifigant byte order, "LittleEndian", or Intel
>      integer format.  Obviously, bigEndian machies will have to
>      do the work here.

Great IDEA! One of the best I have seen lately. Many problems with file
formats etc etc could be solved by this.

I do see some problems however. An int is not the same on any machine. My
personal suggestion would be different. Add 3 types byte, word and dword
(perhaps even qword) to solve the problem of the different word sizes.
I also would like to see an 'exact' modifier which forces an struct or
class to behave exactly as specified (no allignment etc).

To add it all up I would suggest:

types  byte word dword qword
modifiers mso lso  (msb might be confused with most sig bit)
and an exact modifier.

example

exact class EXAM {
   mso byte bStatus;
   mso word wLength;
   ...
};

For those of you afarid of speed problems. The 486 from Intel alread
has a convert command for the purpose of mso<->lso ordering. It is
quite simple for a compiler to use this instruction (only a single
clock cycle there).

It would mean a great step forward in enabling the creation of portable
code if this would be done.

>Sam Christie

Nico E. de Vries
-----------------------------------------------------------------------------
USENET: nevries@cc.ruu.nl                 FIDO      : 2:281/708.1
VOICE : +31-3404-24931 (+31-30-316931)    FAX       : +31-30-312033
BBS   : +31-30-341401 (Nico De_vries)     COMPUSERVE: (coming "soon")

IMPORT Disclaimer, MyPersonalOpinion;            O O  Place reserved for
Complaints about my typostyle to DEV/NUL please.  |   funny joke. Sugestions
I work for BITECH, I don't SPEAK for BITECH.     \_/  apreciated. <== WELL ?