473,789 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does UNALIGNED attribute exist in GNU C?

Hello,

What is equivalent of __unaligned attribute in GNU C?
I've searched for some time and it seems that it just does not exist...

/*
For HP and new Microsoft compilers it works this way:
long_pointer = (some unaligned address)
long_value = (* (__unaligned long *) long_pointer );

This causes the compiler to emit code that gets the value
in some slow but sure way, but avoiding exceptions
*/

No need to suggest workarounds please...

Regards
--PA
Nov 14 '05 #1
18 10077
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Pavel A." <pa*****@NOwrit emeNO.com> writes:
What is equivalent of __unaligned attribute in GNU C?
I've searched for some time and it seems that it just does not exist...


It appears not to. That's probably because it should not be needed
unless your code is buggy. If your code is standard C, the compiler
should have aligned everything nicely for you. However, you didn't
post the code that creates the unaligned pointer.

Also:
- - Some CPUs allow unaligned access.
- - Some operating systems can transparently handle unaligned access on
systems that don't support it.
- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourc eforge.net/>

iD8DBQFCjOFQVcF caSW/uEgRAu+aAKDDQqL P5PeBpB4RHt2Wn8 bGN4lEXwCfQa4U
MDJleeQZG8u63b7 TJZExNog=
=XMLL
-----END PGP SIGNATURE-----
Nov 14 '05 #2
[fu-t set]

in comp.lang.c i read:
What is equivalent of __unaligned attribute in GNU C?
I've searched for some time and it seems that it just does not exist...


correct -- there is nothing standard.

--
a signature
Nov 14 '05 #3
Thanks Roger for your reply.
I was looking how to implement functions like LoadUnalignedLo ng /
StoreUnalignedL ong
(the need for these is obvious... if you get unaligned structure from file
or network etc).
So will do it anyway else.

--PA

"Roger Leigh" <${*******@inva lid.whinlatter. ukfsn.org.inval id> wrote in
message news:87******** ****@hardknott. home.whinlatter .ukfsn.org...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Pavel A." <pa*****@NOwrit emeNO.com> writes:
What is equivalent of __unaligned attribute in GNU C?
I've searched for some time and it seems that it just does not exist...
It appears not to. That's probably because it should not be needed
unless your code is buggy. If your code is standard C, the compiler
should have aligned everything nicely for you. However, you didn't
post the code that creates the unaligned pointer.

Also:
- - Some CPUs allow unaligned access.
- - Some operating systems can transparently handle unaligned access on
systems that don't support it.
- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your

mail. -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourc eforge.net/>

iD8DBQFCjOFQVcF caSW/uEgRAu+aAKDDQqL P5PeBpB4RHt2Wn8 bGN4lEXwCfQa4U
MDJleeQZG8u63b7 TJZExNog=
=XMLL
-----END PGP SIGNATURE-----

Nov 14 '05 #4
"Pavel A." wrote:

I was looking how to implement functions like LoadUnalignedLo ng /
StoreUnalignedL ong (the need for these is obvious... if you get
unaligned structure from file or network etc).
So will do it anyway else.


Please don't toppost. It is not acceptable in c.l.c. See sig
below.

There is no such need. How do you get an "unaligned structure"?
All you can receive from a network of file is some gestalt of
bytes, which should have a defined relationship to a field in a
structure. The details of a structure are not valid outside the
system that created it, and can be freely changed, even by a
compiler upgrade.

--
Some informative links:
news:news.annou nce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
Nov 14 '05 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Pavel A." <pa*****@NOwrit emeNO.com> writes:

[Please don't top-post]
I was looking how to implement functions like LoadUnalignedLo ng /
StoreUnalignedL ong
(the need for these is obvious... if you get unaligned structure from file
or network etc).


I've never seen those non-standard functions. Due to the hideous
naming, I assume they come from MS Windows?

The need for them aside, you could always memcpy to a known aligned
memory location before reading/writing. It should be fairly cheap,
but still less than ideal. If your software is properly written, you
simply won't have alignment issues.
- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourc eforge.net/>

iD8DBQFCkMXUVcF caSW/uEgRAq1GAJ9GYG9 AuzlZcETFP5rGat DYmrDu7gCfX20d
TKSkV3oERlS9U9D F21grf60=
=BlzH
-----END PGP SIGNATURE-----
Nov 14 '05 #6
Roger Leigh <${*******@inva lid.whinlatter. ukfsn.org.inval id> wrote:
"Pavel A." <pa*****@NOwrit emeNO.com> writes:

[Please don't top-post]
I was looking how to implement functions like LoadUnalignedLo ng /
StoreUnalignedL ong
(the need for these is obvious... if you get unaligned structure from file
or network etc).
I've never seen those non-standard functions. Due to the hideous
naming, I assume they come from MS Windows?


You'd say so, but AFAICT not even that.
The need for them aside, you could always memcpy to a known aligned
memory location before reading/writing. It should be fairly cheap,
but still less than ideal.


If you have a halfway decently defined network or file format, you won't
be reading directly into your objects if that's impossible. You'll be
manipulating the byte _values_, rather than their representations in
memory.

Richard
Nov 14 '05 #7
On Thu, 19 May 2005 19:56:17 +0100, Roger Leigh wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Pavel A." <pa*****@NOwrit emeNO.com> writes:
What is equivalent of __unaligned attribute in GNU C?
I've searched for some time and it seems that it just does not exist...


It appears not to. That's probably because it should not be needed
unless your code is buggy.


I respectfully disagree: In networking applications, for performance
reasons (to avoid data copying) one must frequently deal with portions of
buffers that are not correctly aligned.
Nov 14 '05 #8
Thomas Carter wrote:
On Thu, 19 May 2005 19:56:17 +0100, Roger Leigh wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Pavel A." <pa*****@NOwrit emeNO.com> writes:

What is equivalent of __unaligned attribute in GNU C?
I've searched for some time and it seems that it just does not exist...


It appears not to. That's probably because it should not be needed
unless your code is buggy.

I respectfully disagree: In networking applications, for performance
reasons (to avoid data copying) one must frequently deal with portions of
buffers that are not correctly aligned.

That depends on what you mean by unaligned. The C standards don't allow
the kinds of type punning which would place, for example, a long long
int at an odd short int address. Code which does so is non-portable.
Even Microsoft C, in the newer 64-bit versions, gets away from the
requirement to maximize support of 64-bit data located on any 32-bit
boundary, but this NG is about standard C.
If you mean, for example, a string of ints starting at any legal int
boundary, that's the default, and doesn't require any attribute or
pragma. gcc does support specification of higher alignments, such as
those which would allow the use of aligned pair load and store instructions.
Nov 14 '05 #9
On Sat, 18 Jun 2005 14:50:47 +0000, Thomas Carter wrote:
On Thu, 19 May 2005 19:56:17 +0100, Roger Leigh wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Pavel A." <pa*****@NOwrit emeNO.com> writes:
What is equivalent of __unaligned attribute in GNU C?
I've searched for some time and it seems that it just does not exist...


It appears not to. That's probably because it should not be needed
unless your code is buggy.


I respectfully disagree: In networking applications, for performance
reasons (to avoid data copying) one must frequently deal with portions of
buffers that are not correctly aligned.


This is a generalisation which is the for most part wrong. Not totally
wrong but still mostly wrong. However a discussion of why is beyond the
scope of comp.lang.c (i.e. where I am reading this).

Lawrence
Nov 14 '05 #10

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

Similar topics

4
5476
by: Daniel Polansky | last post by:
Is there a way to open file for writing so that the opening fails if the file already exist? This needs to be atomic operation so that it is possible to use the file as a semaphore. As a result, the following coding does not do: if (!file.exist()) { // open the file for writing ... A similar function definitely exists for accessing files in
2
1898
by: glen herrmannsfeldt | last post by:
There is a post in comp.lang.java.machine that says that this group doesn't really exist. I wanted to be sure that it did. -- glen
1
18909
by: Mark Richards | last post by:
The solutions for the following problems seems to be simple but I did not found a (convenient) solution: Assume we have a number of elements of the same type under a common parent e.g. <person ... myattr="aaa">Paul</person> <person ... myattr="bbb">Peter</person> <person ... myattr="ccc">Karl</person> ..... <person ... myattr="ddd">Stan</person>
7
2424
by: LT | last post by:
Hello, I have the following problem. I'm using the CMonthCalCtrl calendar control. I need to emphasize some of days, so I'm handling the MCN_GETDAYSTATE event. The problem is when my handler function is called for the first time during initializing of the application. When I'm calling the CMonthCalCtrl::GetMonthRange method there is an assertion error inside that method: ASSERT(::IsWindow(m_hWnd)); It seems that my event handler is...
2
17899
by: adam | last post by:
hello What query shoul I send to SQL serwer ( in transact SQL language ) to check does some database exist on serwer ? It similar to problem "does some table exist in database" - resolve to it is query: use db_silnik IF EXISTS (SELECT * FROM prad) PRINT 'table exist'
8
3759
by: dmitrey | last post by:
howto check does module 'asdf' exist (is available for import) or no? (without try/cache of course) Thx in advance, D.
2
12629
ADezii
by: ADezii | last post by:
Many times when writing VBA code, we find the need to work with Files in one form or another. Whatever the process may be, we need to be sure that a File is present in a specified location. One Method to guarantee that a File does in fact exist, is to pass the Absolute Path to the File to a Function which will investigate the Path and return a Boolean Value (True/False) indicating whether or not the File exists. The following code segments will...
4
2127
by: s0suk3 | last post by:
I wanted to ask for ways to test whether a path exists. I usually use os.path.exists(), which does a stat call on the path and returns True if it succeeds, or False if it fails (catches os.error). But stat calls don't fail only when a path doesn't exist. I see that, at least on Windows, the instance of the exception has an attribute 'errno' set to 2 when it fails because the path doesn't exist. Is it a portable solution to rely on this...
0
9656
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
9499
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10374
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
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10121
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7519
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
5539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4076
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 we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.