473,396 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

what is word boundary?

Can some one guide me what is word boundary?
google is no good for me for this
thanks in advance
Sep 17 '05 #1
14 19061
On Sun, 18 Sep 2005 00:15:43 +0100, "Singleton"
<ku*****@homecall.co.uk> wrote in comp.lang.c++:
Can some one guide me what is word boundary?
google is no good for me for this
thanks in advance


What made you decide to ask this question here? There is no such term
defined by the C++ language.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Sep 17 '05 #2
I just took c++ exam in brainbnch . one of the question is
Q:)According to the C++ standard, what is an object's internal
representation in memory guaranteed to be?
Choice 1 : Contiguous
Choice 2 : On the stack
Choice 3 : Initialized
Choice 4 : On a word boundary
Choice 5 : On the heap

Even one of the c++ technical test for a company was asking the same
question.
In fact in Google there are many c++ sites talking about problems with word
boundary.
hope you are convinced.

Regards,
S
ignorance is bliss
"Jack Klein" <ja*******@spamcop.net> wrote in message
news:fm********************************@4ax.com...
On Sun, 18 Sep 2005 00:15:43 +0100, "Singleton"
<ku*****@homecall.co.uk> wrote in comp.lang.c++:
Can some one guide me what is word boundary?
google is no good for me for this
thanks in advance


What made you decide to ask this question here? There is no such term
defined by the C++ language.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

Sep 17 '05 #3
Hi,

It depends on how large a word is. On a lot of machines today a word is 32
bit. That means on a word boundary is at address
0
4
8
12
16
etc...

ten years ago or so a word used to be 16 (8086) bits and before that 8 bit
was common (6502, 6800, 6809)

Usually there is a bit of a performance gain working with the processors
native size. So using 32 bits and memory addresses that are on a word
boundary can be more efficient. than memory addresses at non-32 bit -16 bit
or even non 32- non- 16 but 8 bit addresses even the latter is smaller you
might end up with slower code when using those sizes and addresses . in your
code.
--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Singleton" <ku*****@homecall.co.uk> wrote in message
news:43**********@mk-nntp-2.news.uk.tiscali.com...
Can some one guide me what is word boundary?
google is no good for me for this
thanks in advance

Sep 18 '05 #4
"Singleton" writes:
I just took c++ exam in brainbnch . one of the question is
Q:)According to the C++ standard, what is an object's internal
representation in memory guaranteed to be?
Choice 1 : Contiguous
Choice 2 : On the stack
Choice 3 : Initialized
Choice 4 : On a word boundary
Choice 5 : On the heap


In that context, a word is the natural/native amount of data fetched from
memory on a single access by a CPU. A sampling of some of the word sizes
over the years (in bits per word): 6, 8, 15, 16, 18, 24, 30, 32, 36, 51, 60.
And a great many more.
Sep 18 '05 #5
Singleton wrote:
Can some one guide me what is word boundary?
google is no good for me for this
thanks in advance


The size of an int in a C++ compiler should be the same as the size of
a word for the architecture that that compiler targets.

A word is supposed to be the "natural" size in which the computer
ordinarily processes data. For most computers these days that would be
32 bits. So a word boundary on most machines would occur every four
bytes in memory and start at a byte address evenly divisible by 4.

Greg

Sep 18 '05 #6
"Greg" <gr****@pacbell.net> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com
Singleton wrote:
Can some one guide me what is word boundary?
google is no good for me for this
thanks in advance


The size of an int in a C++ compiler should be the same as the size of
a word for the architecture that that compiler targets.

A word is supposed to be the "natural" size in which the computer
ordinarily processes data. For most computers these days that would be
32 bits. So a word boundary on most machines would occur every four
bytes in memory and start at a byte address evenly divisible by 4.

Greg


On Windows, a WORD is 16 bits on 32 bit machines. A DWORD (double word) is
32 bits.

This may well be because a WORD was 16 bits on earlier 16 bit versions of
Windows and its size has been left at 16 bits for backward compatibility
reasons.

--
John Carson

Sep 18 '05 #7

John Carson wrote:
"Greg" <gr****@pacbell.net> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com
Singleton wrote:
Can some one guide me what is word boundary?
google is no good for me for this
thanks in advance


The size of an int in a C++ compiler should be the same as the size of
a word for the architecture that that compiler targets.

A word is supposed to be the "natural" size in which the computer
ordinarily processes data. For most computers these days that would be
32 bits. So a word boundary on most machines would occur every four
bytes in memory and start at a byte address evenly divisible by 4.

Greg


On Windows, a WORD is 16 bits on 32 bit machines. A DWORD (double word) is
32 bits.

This may well be because a WORD was 16 bits on earlier 16 bit versions of
Windows and its size has been left at 16 bits for backward compatibility
reasons.

--
John Carson


Yes, but size of the "int" type in C++ is the one that has to match the
size of a machine word. longs, shorts, and especially typedefs may or
may not match.

In fact the reason that WORD and DWORD exist are to insulate C++ source
code from changes in the size of an int. After all, an int is the type
which is the mostly like to change in size. As it did when the platform
moved from 16 to 32 bits, and presumably will again when it moves from
32 to 64 bits. By using typedefs for integer types, the programmer can
be assured of constant sizes. It allows the programmer to be able to
decide when and how to make the transition to the larger types, instead
of having to do it one day after installing the latest C++ compiler.

Greg

Sep 18 '05 #8
"Greg" <gr****@pacbell.net> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com
John Carson wrote:
"Greg" <gr****@pacbell.net> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com
Singleton wrote:
Can some one guide me what is word boundary?
google is no good for me for this
thanks in advance

The size of an int in a C++ compiler should be the same as the size
of a word for the architecture that that compiler targets.

A word is supposed to be the "natural" size in which the computer
ordinarily processes data. For most computers these days that would
be 32 bits. So a word boundary on most machines would occur every
four bytes in memory and start at a byte address evenly divisible
by 4.

Greg


On Windows, a WORD is 16 bits on 32 bit machines. A DWORD (double
word) is 32 bits.

This may well be because a WORD was 16 bits on earlier 16 bit
versions of Windows and its size has been left at 16 bits for
backward compatibility reasons.

--
John Carson


Yes, but size of the "int" type in C++ is the one that has to match
the size of a machine word. longs, shorts, and especially typedefs
may or may not match.

In fact the reason that WORD and DWORD exist are to insulate C++
source code from changes in the size of an int. After all, an int is
the type which is the mostly like to change in size. As it did when
the platform moved from 16 to 32 bits, and presumably will again when
it moves from 32 to 64 bits. By using typedefs for integer types, the
programmer can be assured of constant sizes. It allows the programmer
to be able to decide when and how to make the transition to the
larger types, instead of having to do it one day after installing the
latest C++ compiler.

Greg


I agree with most of what you say, but in the interests of accuracy would
point out:

1. The distinction that you wish to make between word (lowercase) and the
typedef WORD (uppercase) is not one that is maintained in Windows
programming. I am not defending Windows terminology, just pointing it out.
See here for example:

http://msdn.microsoft.com/library/de...ros/loword.asp

2. 64 bit Windows is already here and an int is still 32 bits (a
controversial decision that could easily have gone the other way, but there
you have it).

--
John Carson

Sep 18 '05 #9
"Singleton" <ku*****@homecall.co.uk> wrote in message
news:43**********@mk-nntp-2.news.uk.tiscali.com...
I just took c++ exam in brainbnch . one of the question is Q:)According to the C++ standard, what is an object's internal
representation in memory guaranteed to be?
Choice 1 : Contiguous
Choice 2 : On the stack
Choice 3 : Initialized
Choice 4 : On a word boundary
Choice 5 : On the heap


The correct answer is Choice 6: None of the above.

Objects with virtual base classes are not always contiguous, which rules out
(1).

The word "stack" appears in the C++ standard only in the context of "stack
unwinding" that occurs as part of exception handling, and in the
descriptions of the library algorithms that deal with stacks.

Objects are not guaranteed to be initialized.

The phrase "word boundary" appears nowhere in the C++ standard.

The word "heap" appears in the C++ standard only in the context of
describing the library algorithms that deal with heaps.
Sep 18 '05 #10
On Sun, 18 Sep 2005 00:42:33 +0100, "Singleton"
<ku*****@homecall.co.uk> wrote in comp.lang.c++:
I just took c++ exam in brainbnch . one of the question is
Q:)According to the C++ standard, what is an object's internal
representation in memory guaranteed to be?
Choice 1 : Contiguous
Choice 2 : On the stack
Choice 3 : Initialized
Choice 4 : On a word boundary
Choice 5 : On the heap


None of these answers is correct according to the C++ standard. And
C++, as I said, does not even define the term "word boundary". This
merely means that Brainbench has made a mistake in their test. In the
past, they have worked to correct such errors when pointed out to
them. I do not know whether they still do so or not.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Sep 18 '05 #11
On 17 Sep 2005 18:26:25 -0700, "Greg" <gr****@pacbell.net> wrote in
comp.lang.c++:
Singleton wrote:
Can some one guide me what is word boundary?
google is no good for me for this
thanks in advance


The size of an int in a C++ compiler should be the same as the size of
a word for the architecture that that compiler targets.


Yes, that is a an intention expressed by the C language standard, and
inherited by C++. But there are C and even some C++ compilers for
architectures that are strictly 8-bit, and have no 16-bit registers at
all, yet here int must still be at least 16 bits.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Sep 18 '05 #12
Andrew Koenig wrote:
"Singleton" <ku*****@homecall.co.uk> wrote in message
news:43**********@mk-nntp-2.news.uk.tiscali.com...
I just took c++ exam in brainbnch . one of the question is

Q:)According to the C++ standard, what is an object's internal
representation in memory guaranteed to be?
Choice 1 : Contiguous


Objects with virtual base classes are not always contiguous,
which rules out (1).


The C++ standard requires that the memory for arrays (and vectors)
must be contiguous. This seems to imply that the objects stored
in the array or vector must also use contiguous memory.

What's your definition of 'contiguous' ?

Sep 18 '05 #13
The word boundary refers to word level aligment in memory. If the word
is 32 bit, it means that words are aligned at addresses that are
divisible by 4.

The following article should help:
http://www.eventhelix.com/RealtimeMa...ndOrdering.htm

--
EventStudio 2.5 - http://www.EventHelix.com/EventStudio
Sequence Diagram Based System Design and Modeling Tool

Sep 19 '05 #14
"Old Wolf" <ol*****@inspire.net.nz> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
Objects with virtual base classes are not always contiguous,
which rules out (1).
The C++ standard requires that the memory for arrays (and vectors)
must be contiguous. This seems to imply that the objects stored
in the array or vector must also use contiguous memory. What's your definition of 'contiguous' ?


Good question. Consider this:

struct A { int a; };
struct B : public virtual A { int b; };
struct C : public virtual A { int c; };
struct D: public virtual B, public virtual C { ind d; };

D d;
B* bp = &d;
C* cp = &d;

Now bp points to an object of type B and cp points to an object of type C.
Each of these objects has a member named a, and because both objects are
subobjects of the same object (namely d), bp->a and cp->a are the same
object. In other words, &bp->a == &cp->a.

The pointer bp points to an object (*bp) of type B, which has two members: b
(defined directly as part of the type) and a (inherited from the base class
A). I think that at the very least, if you say that *bp is contiguous, you
are saying that no other objects appear between bp->a and bp->b. They might
not occupy adjacent addresses, but there can't be any other objects between
them.

Therefore, if *bp is contiguous, bp->a and bp->b are in adjacent memory with
the possible exception of padding or other compiler-generated bookkeeping.

So is *bp contiguous? Well, the answer is either yes or no. If it's no,
then there is such a thing as a discontiguous object. So let's assume that
the answer is yes and forge on. This yes answer implies that bp->a and
bp->b have no other objects between them.

Now let's look at *cp, the object to which cp points. It has two members,
cp->a and cp->c. Is *cp contiguous?

If *cp is contiguous, cp->a and cp->c must have no other objects between
them. However, cp->a is the same object as bp->a, and we have already
established that there is an object (namely bp->b) adjacent to bp->a.
Therefore cp->c cannot be adjacent to cp->a, and *cp cannot be contiguous!

In other words, I have proven that after executing the code shown above, it
is impossible for bp and cp both to point to contiguous objects, according
to a fairly loose definition of contiguity.

Sep 19 '05 #15

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

Similar topics

86
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that:...
11
by: L. Chen | last post by:
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?
13
by: Vijay Kumar R. Zanvar | last post by:
Hello, I have few questions. They are: 1. Is "const char * const *p;" a valid construct? 2. How do I align a given structure, say, at 32-byte boundary? 3. Then, how do I assert that a given...
3
by: Muhammad Farooq-i-Azam | last post by:
Hi, I am trying to define an arp structure but having problem doing so. I think I have define the correct arp structure but I find myself in a strange problem. The size of structure that I have...
10
by: Aj Blosser | last post by:
Hey guys, I have a question for you, I have a setup where I'm sending files through the POST to a php web page, I read the file contents, put that file contents as text into the POST string, and...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
2
by: David | last post by:
Hi, Could PHP be used to take a txt file (or set of txt files) and add a string of characters every X number of words or characters? Say a txt file with 50,000 characters/5,000 words how would...
6
by: Gary Bond | last post by:
Hi All, Being a bit of a newbie with regex, I am confused when using word boundaries. For instance, I want to replace all the stand alone '.5k' that occur in an input string, with 500. In other...
8
by: Avi | last post by:
Hi all, I'm using string Replace(string oldValue, string newValue) and would like it to replace only full words that matches oldValue and not when oldValue is a substring of a larger word. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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...

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.