473,405 Members | 2,154 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,405 software developers and data experts.

Doubt in distinguishing between modules and user-defined types main features.

Hello.

I am reading the book written by Bjarne Stroustrup called " The
C++ Programming Language - Special Edition" and
had a doubt which a think is really important to distinguish between
the main features of modules, namespaces, and
User-Defined types. The text above was copied from page 31.

--------------------------------------------------------

namespace Stack{ // representation
const int max_ size = 200;

struct Rep {
char v[max_ size] ;
int top;
};
const int max = 16; // maximum number of stacks
Rep stacks[max] ; // preallocated stack representations
bool used[max] ; // used[i] is true if stacks[i] is in use

typedef Rep& stack;

void push(stack s, char c) { /* check s for overflow and push c */
}
char pop(stack s) { /* check s for underflow and pop
*/ }
stack create() { /* pick an unused Rep, mark
it used, initialize it, and return a reference to it */ }
void destroy(stack s) { /* mark s unused */ }
}
void f()

{
Stack::stack s1 = Stack: :create() ; / / make a new stack
Stack::stack s2 = Stack: :create() ; / / make another new stack

Stack::push(s1,´c´) ;
Stack::push(s2,´k´) ;

if (Stack::pop(s1) != ´c´) throw Bad_ pop() ;
if (Stack::pop(s2) != ´k´) throw Bad_ pop() ;

Stack::destroy(s1) ;
Stack::destroy(s2) ;
}
" What we have done is to wrap a set of interface functions around
the representation type. How the
resulting ‘‘stack type'' behaves depends partly on how we defined
these interface functions, partly
on how we presented the representation type to the users of Stacks,
and partly on the design of the
representation type itself.
This is often less than ideal. A significant problem is that the
presentation of such ‘‘fake types''
to the users can vary greatly depending on the details of the
representation type – and users ought to
be insulated from knowledge of the representation type. For example,
had we chosen to use a more
elaborate data structure to identify a stack, the rules for assignment
and initialization of
Stack: :stacks would have changed dramatically. This may indeed be
desirable at times. However,
it shows that we have simply moved the problem of providing convenient
stacks from the
Stack module to the Stack: :stack representation type.
More fundamentally, user-defined types implemented through a
module providing access to an
implementation type don't behave like built-in types and receive less
and different support than do
built-in types. For example, the time that a Stack: :Rep can be used
is controlled through
Stack: :create() and Stack: :destroy() rather than by the usual
language rules."
Bjarne Stroustrup

--------------------------------------------------------
The disadvantage of using the module in this way , in my opinion,
is because of creation and
destruction are not directly suported by the language.

My doubt is that I can't visualize a way in which changes will be
necessary in the inicialization and assignment due to modifications in
the representation. Since when creation is performed a reference
is returned, we have exactly the representation previously created, so
I don't understand why "the rules for assignment and initialization of
Stack: :stacks would have changed dramatically".
Thanks,
Guilherme Pinto
Jul 19 '05 #1
1 1975
"Guilherme Pinto" <gu************@urbi.com.br> wrote...
I am reading the book written by Bjarne Stroustrup called " The
C++ Programming Language - Special Edition" and
had a doubt which a think is really important to distinguish between
the main features of modules, namespaces, and
User-Defined types. The text above was copied from page 31.
You mean, the text _below_ was copied.
-------------------------------------------------------- [...] --------------------------------------------------------
The disadvantage of using the module in this way , in my opinion,
is because of creation and
destruction are not directly suported by the language.
What do you mean by that? And what do you know about language if
you are still on page 31?

My doubt is that I can't visualize a way in which changes will be
necessary in the inicialization and assignment due to modifications in
the representation.
If the structure 'Rep' is different, it will likely need to have
special initialisation and assignment implementation. For example,
if 'Rep' uses dynamic memory for the storage (intead of the char
array), you should follow "The Rule Of Three" (look it up).
Since when creation is performed a reference
is returned, we have exactly the representation previously created, so
I don't understand why "the rules for assignment and initialization of
Stack: :stacks would have changed dramatically".


If the representation is different... (see above)

Victor
Jul 19 '05 #2

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

Similar topics

18
by: Mike | last post by:
I'm fairly new to PHP, but a long time Perl coder. This is probably answered somewhere, but I haven't been able to find it. The "strength" behind Perl is in its modules; are there modules...
9
by: Emmanuel Charruau | last post by:
Hi, I am looking for a class or any information which would allow me to make communicate mini-module in c++. I have been looking on the net for some examples of such implementation, but I did...
7
by: Lauren Quantrell | last post by:
At running the risk of asking how big is too big... Is there a rule of thumb or a best practice that says I may have too many modules? I currently have a Access2K app with about 30 code modules,...
2
by: Maziar Aflatoun | last post by:
Hi, I have two sections on one .aspx page. One is a datagrid which lists the current users allowing you to edit them as well and on the bottom of my page I have 'Add a new user' section with...
2
by: Nathan Brady | last post by:
Does anyone know of a way on the server side to distinguish between browser windows on the client's computer? Any help would be greatly appreciated. Thanks, Nathan
0
by: David Rose | last post by:
I have an existing asp.net web application which contains several user controls. Some of these user controls contain other user controls (generic controls) which are located in a subdirectory. Now...
6
by: edu.mvk | last post by:
Do we need to check for error condition when we use new operator in C++ instead of malloc? Thanks.
1
by: GeezerButler | last post by:
According to msdn, this method throws XmlException when "There is a load or parse error in the XML. In this case, the document remains empty." I cannot understand the difference between load...
20
by: william.oram | last post by:
Is there a way to use JavaScript to distinguish between Mac OS X 10.4 and earlier OS X versions like with Windows? browserType.UserAgent outputs the following on a 10.4 machine, which (to me) says...
0
by: Mike TI | last post by:
April 7, 2008 Hi all I am planning to develop a solution that will comprise of about 6-8 integrated modules. Now the user would be signing on to the solution (using module 1) and then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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
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
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...
0
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,...

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.