nbanks@killer.UUCP (Nathan Banks) (06/19/88)
Hi, I am relativly new to usenet, forgive me if this has already been hashed out in this topic area. Has anyone addressed the concept of packed data structs in C? I would like to propose a new (if not already proposed) storage allocator called 'packed'. In writing data communication programs in C I find it very frustrating that C requires such stringent alignment in data ts when so many architectures have no alignment requirements. There are some compiler vendors which allow you to specify an architecture model for the code generator to follow which allows the engineer to define o how large a long, int, short, char is o alignment requirements of the above objects o how fields are allocated (left to right or right to left) o how shorts, ints, longs are allocated most significant part is located at bit x LSP is located at bit y, etc. o should there be holes in structs for alignment purposes or should they be padded? I love C, but something needs to be done about data structure definition. When one is trying to define a data structure in C following the guidelines of a standards board like CCITT, ANSI, T1x1 where objects are defined which may or may not occur on an aligned address, one finds if very difficult to define that data strucuture. Engineers programming in C for the first time find it very frustrating when they define a 3 byte data structure and find out that sizeof (x) returns 4 instead of 3 because of padding. This 'packed' feature would be very nice when applied to fields instead of defaulting to int as K&R specified. My company is currently targeting to a 16 bit architecture with plans to move to a 32 bit architecture. There are lots of field definitions - few people on my project are forcing their own field definitions to padd out to 32 bits using a union. My attempts to get the company to define a standard 16 bit int across both the current 16 bit architecture and the future 32 bit architecture have failed - so far. When you defining a fields to match CCITT field definitions that fit inside an octet, one finds that he must define a char and then define a "template" struct to interrogate the data stored in the char or just define a union. Or define masks to interrogate the data. To myself - none of these methods are as elegant as what I think 'packed' could do for C. I thank Ma Bell, K and R for coming up with this engineer's "dream? " language, but I think we need to adopt some, if not all of the data definition primitives that our European alllies (competitors?) have accomplished in the CHILL programming language. Digital Equipment Corp's Pascal compiler also has some very nice data structure definition primitives similar to CHILL. How may I become part of the ANSI C definition process? Thank you very much for letting me voice my opinions and your recommendations and criticisms would be accepted with much enthusiasm. Nathan Banks Data Communications Software Engineer ISDN/X.25/SS7 -- _ _ ___ Nathan Banks _ _ _ __) UUCP: nbanks@killer.UUCP BELLNet: (214) 964-3174 _ _ ___) USPS: 2701-C W 15th Street Suite 411 Plano, TX 75075-7523 USA