Byte Alignment of Character to 2 byte

Discussion in 'C Programming' started by v.venkatesh@gmail.com, Jul 6, 2005.

  1. Guest

    Hi,

    For one of our design, we had introduced a local array of structures
    which contains the following fields :

    typedef struct {
    W_CHAR ussdService[MAX_CHARACTER];
    W_CHAR ussdCommand[MAX_NUMBER];
    BOOL isTrue;
    } NSussdStruct;


    The above structure is used to store a Ussd string.

    const NSussdStruct UssdString_To_Operation_tbl[]=
    {
    { L"*126#" , ACTIVATE },
    { L"#126#" , DEACTIVATE },
    { L"*#126#" , STATUS_REQUEST },

    }

    We have used the keyword "L" to specify the characters to be word
    aligned in the structure array, so that its compatible with the lower
    layer calls. The above implementation has been verified to be working
    fine on compiler.

    Our question is, this feature a language dependent or compiler
    dependent feature. Any reference to ANSI C would be useful.
    Also, if any one has implemented the 2 byte CHAR assigment statement
    with the keyword "L", can you please let me know if the implementation
    is safe. Also, please suggest if you have a better strategy.
     
    , Jul 6, 2005
    #1
    1. Advertising

  2. On Wed, 06 Jul 2005 01:12:41 -0700, v.venkatesh wrote:

    > Hi,
    >
    > For one of our design, we had introduced a local array of structures
    > which contains the following fields :
    >
    > typedef struct {
    > W_CHAR ussdService[MAX_CHARACTER];
    > W_CHAR ussdCommand[MAX_NUMBER];
    > BOOL isTrue;
    > } NSussdStruct;
    >
    >
    > The above structure is used to store a Ussd string.
    >
    > const NSussdStruct UssdString_To_Operation_tbl[]=
    > {
    > { L"*126#" , ACTIVATE },
    > { L"#126#" , DEACTIVATE },
    > { L"*#126#" , STATUS_REQUEST },
    >
    > }
    >
    > We have used the keyword "L" to specify the characters to be word
    > aligned in the structure array, so that its compatible with the lower
    > layer calls. The above implementation has been verified to be working
    > fine on compiler.


    The sequence L" intoduces a wide character string literal which is a
    standard construct and has elements of type wchar_t.

    > Our question is, this feature a language dependent or compiler dependent
    > feature. Any reference to ANSI C would be useful. Also, if any one has
    > implemented the 2 byte CHAR assigment statement with the keyword "L",
    > can you please let me know if the implementation is safe. Also, please
    > suggest if you have a better strategy.


    While standard wchar_t isn't guaranteed to be 2 bytes or aligned in any
    particular way. Like any other integer type the standard doesn't specify
    representation details such as byte order.

    Whether it is appropriate depends on how the "lower layer calls" are
    specified. IF it is in terms of wchar_t this is fine, if it is in terms of
    a character array then this isn't portable. If there are specific
    alignment requirements beyong those guaranteed by the type you may have to
    use something like malloc() to guarantee alignment portably.

    OTOH it is possible that the "lower layer calls" are specific to
    implementations which provide greater guarantees than standard C and your
    code may be OK.

    Lawrence
     
    Lawrence Kirby, Jul 6, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Rathnow

    JNI with 1 byte alignment crashes JVM

    Dave Rathnow, Nov 7, 2003, in forum: Java
    Replies:
    2
    Views:
    1,800
    Gordon Beaton
    Nov 7, 2003
  2. Ares Lagae

    Byte alignment in union

    Ares Lagae, Aug 25, 2003, in forum: C++
    Replies:
    21
    Views:
    4,223
    Michiel Salters
    Sep 1, 2003
  3. Marco

    byte alignment

    Marco, Jan 21, 2005, in forum: C++
    Replies:
    4
    Views:
    518
    EventHelix.com
    Jan 22, 2005
  4. Shashi

    Byte Alignment

    Shashi, Nov 10, 2003, in forum: C Programming
    Replies:
    4
    Views:
    579
    Thomas Matthews
    Nov 10, 2003
  5. Polaris431
    Replies:
    8
    Views:
    780
    SM Ryan
    Dec 4, 2006
Loading...

Share This Page