473,405 Members | 2,310 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.

meaning of problem statements (Stroustrup, 5.9)

i don't understand the meaning of these 2 problems statements:

2.) What on your system, are the restrictions on pointer types char*,
int* and void* ?
e.g may an "int*" have an odd value ?

caveat: an "int" can have any value odd or even, whatever, "int*" will
only point to it.

8.) Run some tests to see if your compiler generates equivalent code
for iteration using pointers and iteration using indexing. If
different degrees of optimizations are requested , see if and how that
affects the quality of the generated code.

caveat: how can i test the difference, i can't read the binary code

Apr 1 '07 #1
3 1849
arnuld wrote:
i don't understand the meaning of these 2 problems statements:

2.) What on your system, are the restrictions on pointer types char*,
int* and void* ?
e.g may an "int*" have an odd value ?

caveat: an "int" can have any value odd or even, whatever, "int*" will
only point to it.

8.) Run some tests to see if your compiler generates equivalent code
for iteration using pointers and iteration using indexing. If
different degrees of optimizations are requested , see if and how that
affects the quality of the generated code.

caveat: how can i test the difference, i can't read the binary code
Not sure what you meant by "caveat", but I'd suggest you ignore such
"low-level" questions.

--
ROT-13 the email address to reply.
Apr 1 '07 #2
"arnuld" <ge*********@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
>i don't understand the meaning of these 2 problems statements:

2.) What on your system, are the restrictions on pointer types char*,
int* and void* ?
e.g may an "int*" have an odd value ?

caveat: an "int" can have any value odd or even, whatever, "int*" will
only point to it.

8.) Run some tests to see if your compiler generates equivalent code
for iteration using pointers and iteration using indexing. If
different degrees of optimizations are requested , see if and how that
affects the quality of the generated code.

caveat: how can i test the difference, i can't read the binary code
It's asking about alignment. Some computers require that certain types
(such as ints) reside on certain boundaries. Some machines will work if
they are missaligned, just slower.

For example, on my Windows XP box, the compiler will align 4 byte intergers
every 4 bytes. So the memory address has to be divisible by 4. The
compiler will never purposely place an int starting on an odd memory
address. So that this structure. This can be seen most obvoiusly in
structures.

struct Foo
{
char MyChar; // 1 byte
int MyInt; // 4 bytes
};

int main
{
std::cout << sizeof Foo << "\n";
}

What would you expect the output of this program to be? That is, what would
you think the size of a structure containing one character and one 4 byte
interger to be? If you run it I don't think you'll get the answer you first
thought.

Asnwer the rest of the questions (char, void, etc..) for your own excercise.
Apr 1 '07 #3
On 2007-04-01 20:09, arnuld wrote:
i don't understand the meaning of these 2 problems statements:

8.) Run some tests to see if your compiler generates equivalent code
for iteration using pointers and iteration using indexing. If
different degrees of optimizations are requested , see if and how that
affects the quality of the generated code.

caveat: how can i test the difference, i can't read the binary code
The easiest way is probably to make the program loop the test so many
times that any difference in speed becomes noticeable.

#include <iostream>
#include <ctime>

int main()
{
int arr[100];
std::cout << std::time(0) << "\n";

for (int loop = 0; loop < 10000000; ++loop)
for (int i = 0; i < 100; ++i)
++arr[i];

std::cout << std::time(0) << "\n";
return 0;
}
Test different values for the condition in the outer loop until you get
something that takes some time to run. You'll probably don't want to use
too large arrays to loop over since caching effects can then come into play.

As Anand Hariharan said, there's really not much to be learned from
doing these low-level exercises since they won't tell you much about how
things will work in real applications, there's just too many factors
affecting the outcome, cache is only one.

--
Erik Wikström
Apr 1 '07 #4

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

Similar topics

8
by: Bob Keith | last post by:
Hello, all: I am a beginner of C++, and feel confusing about the differences of the following terms regarding pointer. int *a int* a int** a int*& a int *&a
2
by: Yves Touze | last post by:
Hi All, I'm trying to migrate from SQL Server 7.0 to SQL Server 2000. I've got some ASP page which call VB components that retrieve shaped recordsets from SQL Server using the MSDATASHAPE...
5
by: Ritesh | last post by:
Hi All, According to my observation using SP_WHO2 in my database, some INSERT statements are getting blocked by SELECT statements. Though the blocking SELECT statement is having ReadPast hint,...
7
by: John Baker | last post by:
HI: I see the term "Me!" in a lot of Access statements, bit don't quite know what it means. In the same contexts as wondering what the meaning if "is" is, I wonder what the meaning of "Me!" is....
9
by: Qiao Jian | last post by:
I am new to c. Today I just read an h file within which there is statements: #ifndef _RANDOM_H #define _RANDOM_H So what is the meaning or purpose of this statement? When should I use such...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
7
by: arnuld | last post by:
problem: define functions F(char), g(char&) & h(const char&). call them with arguments 'a', 49, 3300, c, uc & sc where c is a char, uc is unsigned char & sc is signed char. whihc calls are legal?...
14
by: arnuld | last post by:
i have 2 problems: 1.) in section 4.2 he uses: bool is_open(File*) i want to know why he uses the pointer, instead of these 2: bool is_open(File) or bool is_open(File&)
18
by: mati | last post by:
Hi The following code works: #include <vector> class C { private: static const int m_static = 2; public: void f(const std::vector<int>& v)
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
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
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...
0
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...

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.