473,778 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_O peration_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 2080
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_O peration_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
1448
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 functions for: - querying the preferred encoding - splitting encoded strings into characters based on an encoding - determining the direction (L to R, R to L) of each character - determining the number of columns used by each character when...
4
17694
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 b;
14
1958
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 C code, especially design a structure, I pay attention to the order and size of member variables. Because, my boss always says that all variables should be aligned by 4byte boundary, if not a data abort will be occurred on a specific machine such...
11
3783
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. How is this adjustment/alignment done? I goolged around alot and wans't able to find how is it done, all it said was what is byte alignment and byte padding.
12
8129
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 raw MMX and SSE power, the starting pointer MUST be starting at a 16 byte memory boundary. In C++ I allocate more memory than needed, and in a second phase I search for the address that starts on a 16 byte boundary. And I then use that new...
1
3180
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 a char b char c } in a 8 byte packing the sizeof structure is 16. Could anyone explain.
20
3531
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 *)a2; // now a1=a2, a1=a2, etc.
8
8437
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 = "aabbccdd"; where aa is the LSB and dd is the MSB.
19
4143
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
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.