473,511 Members | 16,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Address allignment

7 New Member
Hi ,
Can someone please help me to know how can i check that a 32 bit address is alligned or invalid address ? Can it possible by C code?

I am waiting for your reply.

Thanks
mcarthybn
Sep 10 '09 #1
1 1728
donbock
2,426 Recognized Expert Top Contributor
You have to do something pretty tricky to get the compiler to put C variables at locations with improper alignment. On the other hand, if you're parsing a binary file instead of manipulating C variables then alignment might become an issue.

Strategy 1: Avoid alignment problems by only reading the binary file a char at a time. Provide functions to assemble a wider data type from a char sequence. This approach works well with integer data but not so well with floating-point since you aren't supposed to know the implementation-dependent rules for how floating-point numbers are encoded. You have to worry about the endianness of the file.

Strategy 2: Avoid alignment problems by using a text file instead of a binary file. The file expresses integer and floating-point values in ASCII.

Strategy 3: Avoid alignment problems by only reading the binary file a char at a time. Provide a decoder function for each data type. The decoder functions copy sizeof(type) chars into the char-array portion of a union whose other member is the type in question. Return the value of that other union member. This strategy assumes that the file encoding matches the implementation-dependent encoding of your compiler.

Strategy 4: Look up the implementation-dependent alignment rules for your processor. Write a verify-alignment function for each data type; input to these functions is a void* pointer. Each function casts the pointer to a big-enough integral value and tests the low-order bits to see if they match the required alignment of the data type. This tells you if there is an alignment error, but it doesn't help you read misaligned data.
Sep 10 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

21
15656
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
1
1897
by: Anthony | last post by:
Hi, I've got a question about the allignment of data in a structure. What happens in memory when i declare the following struct A { int x; } stuct B : public A {
8
4574
by: YAN | last post by:
Hi, I want to get the mac address from a machine, which i have the IP address of that machine, how can i do that? I know how to get the mac address of the local machine from the following code: ...
12
2439
by: johny smith | last post by:
I am trying to figure out a way to print the address of what called a certain function once inside the function. I am assuming that this information is on the stack somewhere. But can someone...
7
21269
by: Privacy Advocate | last post by:
//crossposted to: comp.lang.javascript, alt.comp.lang.javascript in an effort to get factual answers from JavaScript experts// Simply put; Is it possible to obtain the real (actual) IP address of...
33
3118
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
1
1413
by: Aitham alama | last post by:
How can i make a dynamically created web label control to to be Center allignment Thanks
4
6271
by: andreas.w.h.k. :-\) | last post by:
How do I change the address location in the wsdl <wsdl:port name="SearchSoap12" binding="tns:SearchSoap12"> <soap12:address location="http://searchservices/engine/search.asmx" /> </wsdl:port> ...
1
2922
by: Phoenix_ver10 | last post by:
I have a mailing list with multiple names going to the same addresses. I need one address with all the names for that address on it. I checked out the example on microsoft's site, but A: It doesn't...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7353
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,...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7508
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...
0
5662
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,...
1
5063
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...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
446
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...

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.