473,770 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what does "strict alignment" mean?

The standard says that a char* or void* pointer has the least strict
alignment. But I do not know what is a strict alignment. What does that
mean?
Nov 14 '05 #1
11 8904
L. Chen wrote:

The standard says that a char* or void* pointer has the least strict
alignment. But I do not know what is a strict alignment.
What does that mean?


An object of type char, can exist at any byte address.
Other types, may only be able to exist at some addresses.

N869
3.1
[#1] alignment
requirement that objects of a particular type be located on
storage boundaries with addresses that are particular
multiples of a byte address

--
pete
Nov 14 '05 #2

"pete" <pf*****@mindsp ring.com> wrote in message
news:41******** ***@mindspring. com...
L. Chen wrote:

The standard says that a char* or void* pointer has the least strict
alignment. But I do not know what is a strict alignment.
What does that mean?


An object of type char, can exist at any byte address.
Other types, may only be able to exist at some addresses.

Or, on the most common CPUs, performance may drop by 70% or more if they are
not so aligned.
Nov 14 '05 #3

"L. Chen" <ch*******@citi z.net> wrote

The standard says that a char* or void* pointer has the least strict
alignment. But I do not know what is a strict alignment. What does that
mean?

On some machines, it is not possible to read certain types except on word
boundaries. For instance, if integers are 32 bits

Load Accumulator 0x80000001 /* error, not a boundary */
Load Accumulator 0x80000004 /* ok. 32 bit boundary */

In order to produce efficient code, the C compiler will respect these
restrictions, for instance inserting padding bits in structures and
returning values from malloc() aligned on the strictest boundary.

One of the quirks of C is that "char" means "byte". By definition, a byte is
the smallest addressable unit of memory, so chars must have the least strict
alignment. Any address can contain a char.
Nov 14 '05 #4
"Malcolm" <ma*****@55bank .freeserve.co.u k> writes:
One of the quirks of C is that "char" means "byte". By definition, a byte is
the smallest addressable unit of memory, so chars must have the least strict
alignment. Any address can contain a char.


What I think you mean is, a 'char' is the smallest unit of memory that
C guarantees you can address in C. But there's nothing preventing a
machine architecture that is addressable down to a single bit having a
C implementation where 'char' is 8 bits and only (bit) addresses that
were zero mod 8 were used in that C implementation. Right? This is
different from saying any [machine] address can contain a char.
Nov 14 '05 #5
Tim Rentsch wrote:

"Malcolm" <ma*****@55bank .freeserve.co.u k> writes:
One of the quirks of C is that "char" means "byte".
By definition, a byte is the smallest addressable unit of memory,
so chars must have the least strict alignment.
Any address can contain a char.


What I think you mean is, a 'char' is the smallest unit of memory that
C guarantees you can address in C.


That's actually more like what a 'byte' is.

N869
3. Terms and definitions
3.4
[#1] byte
addressable unit of data storage large enough to hold any
member of the basic character set of the execution
environment
[#2] NOTE 1 It is possible to express the address of each
individual byte of an object uniquely.
[#3] NOTE 2 A byte is composed of a contiguous sequence of
bits, the number of which is implementation-defined. The
least significant bit is called the low-order bit; the most
significant bit is called the high-order bit.

--
pete
Nov 14 '05 #6
pete <pf*****@mindsp ring.com> writes:
Tim Rentsch wrote:

"Malcolm" <ma*****@55bank .freeserve.co.u k> writes:
One of the quirks of C is that "char" means "byte".
By definition, a byte is the smallest addressable unit of memory,
so chars must have the least strict alignment.
Any address can contain a char.


What I think you mean is, a 'char' is the smallest unit of memory that
C guarantees you can address in C.


That's actually more like what a 'byte' is.

N869
3. Terms and definitions
3.4
[#1] byte
addressable unit of data storage large enough to hold any
member of the basic character set of the execution
environment
[#2] NOTE 1 It is possible to express the address of each
individual byte of an object uniquely.
[#3] NOTE 2 A byte is composed of a contiguous sequence of
bits, the number of which is implementation-defined. The
least significant bit is called the low-order bit; the most
significant bit is called the high-order bit.


Right. 'char' is the type, 'byte' is the name for the unit of memory.

My point was, what C thinks of as a byte is not necessarily the
smallest addressable unit in the machine architecture. Even a machine
that had 8-bit addressable units could have a C implementation where
'bytes' were 16 bits (and that might even make sense if the local
character set were something unicode-like).

Nov 14 '05 #7

"Tim Rentsch" <tx*@alumnus.ca ltech.edu> wrote in message
news:kf******** *****@alumnus.c altech.edu...
pete <pf*****@mindsp ring.com> writes:
Tim Rentsch wrote:

"Malcolm" <ma*****@55bank .freeserve.co.u k> writes:

> One of the quirks of C is that "char" means "byte".
> By definition, a byte is the smallest addressable unit of memory,
> so chars must have the least strict alignment.
> Any address can contain a char.

What I think you mean is, a 'char' is the smallest unit of memory that
C guarantees you can address in C.


That's actually more like what a 'byte' is.

N869
3. Terms and definitions
3.4
[#1] byte
addressable unit of data storage large enough to hold any
member of the basic character set of the execution
environment
[#2] NOTE 1 It is possible to express the address of each
individual byte of an object uniquely.
[#3] NOTE 2 A byte is composed of a contiguous sequence of
bits, the number of which is implementation-defined. The
least significant bit is called the low-order bit; the most
significant bit is called the high-order bit.


Right. 'char' is the type, 'byte' is the name for the unit of memory.

My point was, what C thinks of as a byte is not necessarily the
smallest addressable unit in the machine architecture. Even a machine
that had 8-bit addressable units could have a C implementation where
'bytes' were 16 bits (and that might even make sense if the local
character set were something unicode-like).


Thank you. I have one more question.
Then, if there are two pointers,

int* pn;
double* pd;

is the alignment requirement of pd stricter than that of pn ?
Nov 14 '05 #8
On Mon, 11 Oct 2004 10:52:07 +0800
"L. Chen" <ch*******@citi z.net> wrote:

<snip>
Thank you. I have one more question.
Then, if there are two pointers,

int* pn;
double* pd;

is the alignment requirement of pd stricter than that of pn ?


No. The standard does not impose any restrictions on what alignment the
implementation uses. It would be perfectly legal, although not very
sensible, to produce an implementation where int* pn had an allignment
requirement of 5 and double *pd had an alignment requirement of 3. Yes,
I did deliberately choose prime numbers!
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #9
L. Chen wrote:
Thank you. I have one more question.
Then, if there are two pointers,

int* pn;
double* pd;

is the alignment requirement of pd stricter than that of pn ?


Can't say.

Alignment requirements, go by type.
Alignment requirements are related to size, but two types
of the same size may have different alignment requirements.
While I would expect sizeof double to be larger than
sizeof int usually, it doesn't have to be.

--
pete
Nov 14 '05 #10

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

Similar topics

1
2595
by: ed | last post by:
Folks, I'm attempting to write some OOP with the use strict pragma on an I'm just not getting it to work. Here's an example #!/usr/bin/perl -w use strict; use Automobile; my $file = new Automobile;
14
4096
by: J. Campbell | last post by:
I posted a question some time back about accessing a char array as an array of words. In order not to overrun the char array, I padded it with enough 0x00 bytes to ensure that when accessed as words I wouldn't overrun the array. I was told that this is dangerous and that there could be alignment problems if, for example, I wanted to access the char array elements from non-even multiples of sizeof(int). For example, if I had the array: ...
3
20855
by: signuts | last post by:
I am wondering what it means when a pointer is aligned? Could someone perhaps enlighten me or point me in the right direction? Thank you in advance. -- Sig
5
3914
by: Hendrik Schober | last post by:
Hi, we just run into the problem, that "default" alignment in the project properies dialog seem to be different. We have a project that's a DLL, which is linked with a couple of LIBs. All are with the same solution. All had "Default" set in the "Struct Member Alignment" entry. After some assembler debugging we found out that a struct member that is a member function pointer in
1
6817
by: Andy Crawford | last post by:
Even though I have set Strict Off, it is still on, thus causing this error. Here is the code in a templated Column of a DataGrid: (XPpro, Framework 1.1) <ItemTemplate> <TABLE width="100%"> <TR> <TD class="gridItemStyleNormal" align="left" width="50%"><%# Databinder.Eval(Container.DataItem, "CustomerName") %></TD> <TD class="gridItemStyleNormal" align="left" width="30%"><%# Databinder.Eval(Container.DataItem, "BusinessCategoryDesc")...
3
1358
by: ianakapilotlight | last post by:
We are in the process of moving from .net 1.1 to 2.0 and I dont seem to be able to resolve this problem. In VS2003 the Option Strict was swtiched on in the options menu and this was stored in a project file. In VS2005 there is no project file so this is now stored in the web.config. My web.config shows this :- <compilation debug="true" strict="true" explicit="true">
9
3054
by: Oliver Block | last post by:
Hi, what is the most elegent way to center an image inside a web page. The image is radomly chosen by a cgi script may be 300x400 or 400x300. Are there any alignment commands for images?
0
1250
by: Jean-François Michaud | last post by:
Hello, I was wondering if there was a way around leader-alignment. XSF V3.4 from Antenna House seems to be a very powerful FO -> PDF converter, but it doesn't support this particular attribute from fo:leader. It doesn't support leader-pattern-width either but this can be bypassed by using leader-pattern="use-content" as such: <fo:leader leader-pattern="use-content"> . </fo:leader>
2
1708
by: TomB | last post by:
Take a look at these pages: http://deimos.curious.be/~dusk/test/index.html http://deimos.curious.be/~dusk/test/index2.html They are the exact same code except for the doctype, which isn't included in the index2.html file so it renders in "quirks" mode. However, the way it renders in "quirks" mode is (almost) exactly how I expected the page to render. I want the overflow scrollbar on the
0
9618
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
10260
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...
1
10038
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,...
0
9906
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
8933
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...
0
6712
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
5354
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...
1
4007
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
3
2850
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.