Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Byte Alignment of Character to 2 byte

Reply
Thread Tools

Byte Alignment of Character to 2 byte

 
 
v.venkatesh@gmail.com
Guest
Posts: n/a
 
      07-06-2005
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.

 
Reply With Quote
 
 
 
 
Lawrence Kirby
Guest
Posts: n/a
 
      07-06-2005
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









 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert a 4 byte character string to its equivalent 4 byte integer value? Polaris431 C Programming 8 12-04-2006 07:00 AM
byte alignment Marco C++ 4 01-22-2005 01:41 PM
Byte Alignment Shashi C Programming 4 11-10-2003 09:24 PM
JNI with 1 byte alignment crashes JVM Dave Rathnow Java 2 11-07-2003 08:14 AM
Byte alignment in union Ares Lagae C++ 21 09-01-2003 03:49 PM



Advertisments