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? 11 8749
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
"pete" <pf*****@mindspring.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.
"L. Chen" <ch*******@citiz.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.
"Malcolm" <ma*****@55bank.freeserve.co.uk> 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.
Tim Rentsch wrote: "Malcolm" <ma*****@55bank.freeserve.co.uk> 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
pete <pf*****@mindspring.com> writes: Tim Rentsch wrote: "Malcolm" <ma*****@55bank.freeserve.co.uk> 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).
"Tim Rentsch" <tx*@alumnus.caltech.edu> wrote in message
news:kf*************@alumnus.caltech.edu... pete <pf*****@mindspring.com> writes:
Tim Rentsch wrote: "Malcolm" <ma*****@55bank.freeserve.co.uk> 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 ?
On Mon, 11 Oct 2004 10:52:07 +0800
"L. Chen" <ch*******@citiz.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.
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
"pete" <pf*****@mindspring.com> wrote in message
news:41**********@mindspring.com... 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.
Perhaps more to the point, alignment requirement for double may be stricter
than for long long int. Certain compilers implement moves of double as
(normally slower) long long int moves, in order to avoid misalignment
penalty.
"Tim Rentsch" <tx*@alumnus.caltech.edu> wrote 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).
"char" is a C word, whilst "byte" is a broader concept. K and R made a
mistake by calling "chars" (a variable holding a character) and "bytes" (the
smallest adressable unit of memory) the same thing. As it happens in English
it makes sense to store characters in eight bits, which is also a common
choice for the size of a byte, but this doesn't hold for other languages and
other architectures.
The fact that an "unsigned char" holds a byte is just something we have to
live with, and the problem is further confounded when C pointers differ from
architecture addresses, whether to support multi-byte chars or to implement
8-bit chars on machines where the underlying byte size is 32 bits. So we can
talk about C bytes and hardware bytes. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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
|
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...
|
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%">...
|
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...
|
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?
|
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...
|
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...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |