473,395 Members | 1,948 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,395 software developers and data experts.

confused about arrays

I have a header for a c++ class I am using (from IBM WebSphere
DataStage):

....
// ---------------------------
// --- assignment operator ---
// ---------------------------

/**
If isFixedLength() is true, copies min(length(),
rhs.length()) characters from rhs into this string.
If less than length() characters are copied, the
balance of the length() is right-filled with pad
characters.
If isBoundedLength() is true, silently clamps the copied
length according to the bound.
Only the string value is copied; attributes such as
fixed-length, pad char, etc. are not copied.
@note For variable-length strings, it is not necessary to call
setLength() before calling this function.
*/
APT_BasicString& operator= (const APT_BasicString& rhs);

/**
* See APT_BasicString& operator= (const APT_BasicString& rhs).
*/
APT_BasicString& operator= (const C* rhs);

/**
* See APT_BasicString& operator= (const APT_BasicString& rhs).
*/
APT_BasicString& operator= (C c);

....etc.

And I have a program that does the following:

APT_String depen[15],frst[15];
int i;
....
//some code that assigns data to depen[0..14]

for(i=0;i<14;i++){
frst[i]=depen[i];
}
Question: Am I copying the values or pointers of the strings in depen?

I am asking because after that code I change the values of depen[0..14]
and later in the code frst does not have the content I am expecting
(The original unchanged, that is). Of course it also could be that my
logic is messed up somewhere else but I just wanted to make sure I am
understanding this aspect of c++ correctly.

Oct 6 '05 #1
2 1619
pr*******@latinmail.com wrote:
I have a header for a c++ class I am using (from IBM WebSphere
DataStage):

...
// ---------------------------
// --- assignment operator ---
// ---------------------------

/**
If isFixedLength() is true, copies min(length(),
rhs.length()) characters from rhs into this string.
If less than length() characters are copied, the
balance of the length() is right-filled with pad
characters.
If isBoundedLength() is true, silently clamps the copied
length according to the bound.
Only the string value is copied; attributes such as
fixed-length, pad char, etc. are not copied.
@note For variable-length strings, it is not necessary to call
setLength() before calling this function.
*/
APT_BasicString& operator= (const APT_BasicString& rhs);

/**
* See APT_BasicString& operator= (const APT_BasicString& rhs).
*/
APT_BasicString& operator= (const C* rhs);

/**
* See APT_BasicString& operator= (const APT_BasicString& rhs).
*/
APT_BasicString& operator= (C c);

...etc.

And I have a program that does the following:

APT_String depen[15],frst[15];
int i;
...
//some code that assigns data to depen[0..14]

for(i=0;i<14;i++){
Should be

for(i=0;i<15;i++){

Your arrays are size 15 not 14.
frst[i]=depen[i];
}
Question: Am I copying the values or pointers of the strings in depen?
Values, I see no pointers anywhere. To be precise you are invoking the
arrsignment operator of APT_String. What that does depends of how it was
written, you will have to consult the documentation. But the obvious
sensible thing would be for APT_String to have been written so that
copying it was like copying a value not a pointer.

I am asking because after that code I change the values of depen[0..14]
and later in the code frst does not have the content I am expecting
(The original unchanged, that is). Of course it also could be that my
logic is messed up somewhere else but I just wanted to make sure I am
understanding this aspect of c++ correctly.


OK, well that is evidence that APT_String has not been sensibly written
(in my view). But really no-one here can answer this question (unless
they happen to know about APT_String), you need to consult your
documentation.

Another way would be to write a simple program

int main()
{
APT_String x;
// code to assign value to x
APT_String y;
y = x;
// code to change value of y
// code to see if value of x has also changed
}

in other words write a really simple program to test the hypothesis. I
still would be surprised if copying an APT_String is like copying a
pointer, I would expect that you've messed up somewhere else (no offense
meant) but I could easily be wrong.

John
Oct 6 '05 #2
Thanks,

the APT_String class does indeed copy by value confirming your (and my
initial) assumtion. The algorithm was correct also.

After some madness I figured out what the problem was: When I made the
changes to this routine some changes to the routine that calls this one
were made and the order of the input data passed to it was
inadvertently changed. This resulted in inverted rows in the output.
Fixed the order of the input data and voila! everything worked like a
charm. (duh)

Thanks for your tip, at least I discarded that hypothesis and started
looking elsewhere.

Oct 7 '05 #3

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

Similar topics

13
by: agentxx04 | last post by:
Hi. Our assignment was to creat a program that can find the average, median & mode of a #of integers. Here's my program: #include<stdio.h> int main() { int item; int a, b, t, mode; int...
9
by: vijay | last post by:
Hello, I am new to C Programming and just started reading K&R. I was about to finish the pointers chapter but got very confused with: 1. int arr; >From what I have read, arr is a pointer to...
5
by: Zenobia | last post by:
Hello, I want to keep a list references to database records being accessed. I will do this by storing the record keys in a list. The list must not contain duplicate keys. So I check the...
20
by: mechanicfem | last post by:
I thought (as they're in c99) that flexible arrays were there for a number of reasons - but I also thought they'd be great for stepping into structures (say) that were aligned in memory after (say)...
36
by: utab | last post by:
Dear, I have experince in C( numerical projects, like engineering problems, scientific applications) I have the basic notion of C++ also, I have read Accelerated C++ until Chapter 7, however it...
0
by: Pascal Flückiger | last post by:
Hello I have a tcl-webservice based on tclsoap/tclhttpd. A function returns an array of structs. The problem (someone from csharp.de ng told me): The Soap-functionality of the .Net Framework...
7
by: Schraalhans Keukenmeester | last post by:
According to www.c-faq.com (Q6.6) -------- Q: If you can't assign to arrays, then how can int f(char str) { if(str == '\0') str = "none"; ...
15
by: rEvolution27 | last post by:
I'm a c++ newbie here, trying out some stuff and when I try to compile this: void create() { char name; cout << "Creating a new timetable /n Please type a name for this timetable"; cin >name;...
19
by: arnuld | last post by:
i am trying to understand arrays and char. Stroustrup says, this a string literal: "this is a string literal" he says it is of type /const char/. he also says, because of keeping...
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: 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:
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
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
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
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.