473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Byte Alignment of Character to 2 byte

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.

Nov 15 '05 #1
1 2059
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



Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ian Ward | last post by:
I hope to add support for multi-byte encoded and bidirectional text to my curses-based UI library: http://excess.org/urwid/ I would like to support whatever encoding the user likes. Are there...
4
by: Shashi | last post by:
Can somebody explain how the byte alignment for structures work, taking the following example and considering: byte of 1 Byte word of 2 Bytes dword of 4 Bytes typedef struct { byte a; word...
14
by: gamja | last post by:
Hi all. This is my first post on this group. Nice to meet you, cool guys~! I'm on system programming on various embedded systems and understand very well the byte alignment issues. When I write...
11
by: Taran | last post by:
Hi all, I was wondering how does address alignment to x byte boundary is done. For example, if I say "adjust the requested size to be on a 4-byte boundary" or for that matter 8 byte boundary....
12
by: Olaf Baeyens | last post by:
I am porting some of my buffer class code for C++ to C#. This C++ class allocates a block of memory using m_pBuffer=new BYTE; But since the class is also used for pointers for funtions that uses...
1
by: Gajendra | last post by:
How does the byte packing and the byte alignment work in VC++ compiler? What is the effect of #pragma pack(n) on the alignment and byte packing for example while using the structur struc double...
20
by: quantumred | last post by:
I found the following code floating around somewhere and I'd like to get some comments. unsigned char a1= { 5,10,15,20}; unsigned char a2= { 25,30,35,40}; *(unsigned int *)a1=*(unsigned int...
8
by: Polaris431 | last post by:
I have a buffer that holds characters. Four characters in a row represent an unsigned 32 bit value. I want to convert these characters to a 32 bit value. For example: char buffer; buffer =...
19
by: glchin | last post by:
Does a compiler guarantee that the variable w below is placed on an eight-byte aligned address? void myFunction( long iFreq ) { const double w = two_pi * iFreq; ... ... }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.