|
From: Santiago P. C. <San...@yd...> - 2002-07-30 08:22:53
|
Hi Ramana,
Please have in mind that you are managing 'strings' (let's say: objects of
string class) and not char arrays...
Your assertion should be right ONLY if you were managing char arrays, but
you are handling string objects.
Please have a look at the following code (compile & run it):
<CODE>
#include <iostream>
#include <string>
int main(int argc, char* argv[])
{
using std::cout;
string myVariable1 = "Some content";
string myVariable2 = "Some different content";
myVariable1.resize( myVariable2.size() );
cout << "Variable No. 1 content: " << myVariable1 << endl;
cout << "Variable No. 2 content: " << myVariable2 << endl;
// The size of the string object may be different than the number of
chars stored
if ( myVariable1.size() != sizeof(myVariable1) )
{
cout << "This is an error!!!" << endl;
}
return 0;
}
</CODE>
Just take a closer look to string methods (like size(), length() and so on)
and use them instead of sizeof !!! ;o)
Hope this helps!!!
Regards, Santy
-----Original Message-----
From: Ramana Kumar [mailto:ra...@my...]
Sent: Tuesday, July 30, 2002 9:40 AM
To: C++
Subject: [Dev-C++] sizeof array
I have the feeling that I am missing something fundamental in my
understanding of the sizeof operator or multidimensional arrays when I get
these results:
--------snip----------
String Substitutions[][2] = //String is a user-defined class
{
"I'M","I AM",
"YOU'RE","YOU ARE",
"HE'S","HE IS",
"SHE'S","SHE IS",
"IT'S","IT IS",
"WE'RE","WE ARE",
"THEY'RE","THEY ARE"
};
bool SomeFunc(String s)
{
s.Substitute(Substitutions); //pass multidimensional array to member
function }
--------snip----------
--------snip----------
void String::Substitute(String sub[][2]) //passed Substitutions here {
String ss[][2] = //exact replica of Substitutions {
"I'M","I AM",
"YOU'RE","YOU ARE",
"HE'S","HE IS",
"SHE'S","SHE IS",
"IT'S","IT IS",
"WE'RE","WE ARE",
"THEY'RE","THEY ARE"
};
if(sizeof(ss)!=sizeof(sub)) //sizeof identical arrays
{
MessageBox(NULL,"Error","Error",MB_OK);
}
}
--------snip----------
Compiles fine. The MessageBox always appears when running, indicating that
the size of those two identical arrays are different! Obviously something to
do with pointers and passing arrays to functions or something like this is
messing up the operation of the sizeof operator. Anyone have any ideas?
-------------------------------------------------------
This sf.net email is sponsored by: Dice - The leading online job board for
high-tech professionals. Search and apply for tech jobs today!
http://seeker.dice.com/seeker.epl?rel_code=31
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--------------------------------------------------------------------------------------
This message and any files transmitted with it are confidential and intended solely
for the use of the individual or entity to whom they are addressed. No confidentiality
or privilege is waived or lost by any wrong transmission.
If you have received this message in error, please immediately destroy it and kindly
notify the sender by reply email.
You must not, directly or indirectly, use, disclose, distribute, print, or copy any
part of this message if you are not the intended recipient. Opinions, conclusions and
other information in this message that do not relate to the official business of
Ydilo Advanced Voice Solutions, S.A. shall be understood as neither given nor endorsed by it.
--------------------------------------------------------------------------------------
|
|
From: Ramana K. <ra...@my...> - 2002-07-31 11:19:08
|
thanks ioannis, i have briefly read your reply and it is what i had feared.
is there any way to implement what i had before so that the sizeof operator
reports the size as if it were a local array? for example, can i pass the
array to the function by reference or dereference the pointer that is
passed?
-----Original Message-----
From: Ioannis Vranos [mailto:no...@ho...]
Sent: Wednesday, 31 July 2002 9:15 PM
To: 'Ramana Kumar'
Subject: RE: [Dev-C++] sizeof array
sizeof() reports the total size of the array when it is used in the
scope of its definition.
When you use an array as an argument of a function in reality it is not
an array but a pointer.
consider the following example:
void makea(char array[100])
{
while(*array)
*array++='a';
}
int main()
{
char somearray[500];
for(unsigned long i=0; i<sizeof(somearray)-2; i++)
somearray[i]='s';
somearray[sizeof(somearray)-1]='\0';
makea(somearray);
}
void makea(char array[100]) is equivallent to void makea(char *array)
and void makea(char array[])
So sizeof(array) when applied inside the makea() is equivallent to
sizeof(char *).
array there is char *array.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|
|
From: Carlos d. M. <cg...@wo...> - 2002-07-31 12:13:17
|
Do you mean having an array array of size n and call a function
function(array); and that function calculate the size in it?
I don't know about any "built-in" function for do so, but it could be don=
e
adding a special member which should be added as the last member, so you =
can
search it from the begin of the array, so you can consider the size as eq=
ual to
the location of that member plus one, or it has a size of that subindex o=
f
elements you mind plus one member you don't mind, and whenever you can ne=
ed
reallocate memory or adding members you must have space for that last, an=
d when
adding, start adding substituting that member. And then work considering =
the
matter of having one member which you don't use.
For example, if it is an array of chars, that member is evident, you only=
need
to search for '\0', but in chars* it is used, and has sense but in other =
cases
the equivalent you use not. You can have an array of positive values, so =
you
can use -1 as that member.
for(counter =3D 0; testmember !=3D itemextra; counter++){
itemextra =3D array[counter];
size =3D counter + 1;
}
[size++]
You can say this size++ or not depending on whether you want size mean si=
ze of
the whole array including the last member or not. Or you can reallocate =
to
adjust the size to the array you need without that member and then work w=
ith it
as if you didn't use that member, and at the end you can realloc and add =
it, or
whatever you need or want to do.
Ramana Kumar escribi=F3:
> thanks ioannis, i have briefly read your reply and it is what i had fea=
red.
> is there any way to implement what i had before so that the sizeof oper=
ator
> reports the size as if it were a local array? for example, can i pass t=
he
> array to the function by reference or dereference the pointer that is
> passed?
>
> -----Original Message-----
> From: Ioannis Vranos [mailto:no...@ho...]
> Sent: Wednesday, 31 July 2002 9:15 PM
> To: 'Ramana Kumar'
> Subject: RE: [Dev-C++] sizeof array
>
> sizeof() reports the total size of the array when it is used in the
> scope of its definition.
>
> When you use an array as an argument of a function in reality it is not
> an array but a pointer.
>
> consider the following example:
>
> void makea(char array[100])
> {
> while(*array)
> *array++=3D'a';
> }
>
> int main()
> {
> char somearray[500];
>
> for(unsigned long i=3D0; i<sizeof(somearray)-2; i++)
> somearray[i]=3D's';
>
> somearray[sizeof(somearray)-1]=3D'\0';
>
> makea(somearray);
> }
>
> void makea(char array[100]) is equivallent to void makea(char *array)
> and void makea(char array[])
>
> So sizeof(array) when applied inside the makea() is equivallent to
> sizeof(char *).
>
> array there is char *array.
>
> Ioannis
>
> * Ioannis Vranos
> * Programming pages: http://www.noicys.cjb.net
> * Alternative URL: http://run.to/noicys
>
> -------------------------------------------------------
> This sf.net email is sponsored by: Dice - The leading online job board
> for high-tech professionals. Search and apply for tech jobs today!
> http://seeker.dice.com/seeker.epl?rel_code=3D31
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Ramana K. <ra...@my...> - 2002-07-31 12:36:05
|
thank you carlos
i had in fact thought of using a special array member at the end, and thank
you for illustrating implentation of this so beautifully.
i'm afraid this may have to be the way i do it in the end, unless i simply
don't pass the array and declare it locally.
but since the array is in fact a two-dimensional array full of instances of
my own String class, adding a "terminating character" will involve creating
too much arbitrary code for my liking. I am still dreaming of the
possibility of sizeof-ing the array with the built in operator, if anyone
knows how to do this correctly. In fact, i am highly curious about the
workings of the sizeof operator. I realize that since passing an array to a
function is actually passing a pointer to the first object ( is this x[0] or
x[0][0] in a multidimensional array?), the sizeof operator gets the size of
that pointer... or does it? what are you passing the operator when the array
is local?
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Carlos García
del Monte
Sent: Wednesday, 31 July 2002 10:09 PM
To: dev-cpp-users-list
Subject: Re: [Dev-C++] sizeof array
Do you mean having an array array of size n and call a function
function(array); and that function calculate the size in it?
I don't know about any "built-in" function for do so, but it could be done
adding a special member which should be added as the last member, so you can
search it from the begin of the array, so you can consider the size as equal
to the location of that member plus one, or it has a size of that subindex
of elements you mind plus one member you don't mind, and whenever you can
need reallocate memory or adding members you must have space for that last,
and when adding, start adding substituting that member. And then work
considering the matter of having one member which you don't use.
For example, if it is an array of chars, that member is evident, you only
need to search for '\0', but in chars* it is used, and has sense but in
other cases the equivalent you use not. You can have an array of positive
values, so you can use -1 as that member.
for(counter = 0; testmember != itemextra; counter++){
itemextra = array[counter];
size = counter + 1;
}
[size++]
You can say this size++ or not depending on whether you want size mean
size of the whole array including the last member or not. Or you can
reallocate to adjust the size to the array you need without that member and
then work with it as if you didn't use that member, and at the end you can
realloc and add it, or whatever you need or want to do.
Ramana Kumar escribió:
thanks ioannis, i have briefly read your reply and it is what i had
feared.
is there any way to implement what i had before so that the sizeof
operator
reports the size as if it were a local array? for example, can i pass
the
array to the function by reference or dereference the pointer that is
passed?
-----Original Message-----
From: Ioannis Vranos [mailto:no...@ho...]
Sent: Wednesday, 31 July 2002 9:15 PM
To: 'Ramana Kumar'
Subject: RE: [Dev-C++] sizeof array
sizeof() reports the total size of the array when it is used in the
scope of its definition.
When you use an array as an argument of a function in reality it is not
an array but a pointer.
consider the following example:
void makea(char array[100])
{
while(*array)
*array++='a';
}
int main()
{
char somearray[500];
for(unsigned long i=0; i<sizeof(somearray)-2; i++)
somearray[i]='s';
somearray[sizeof(somearray)-1]='\0';
makea(somearray);
}
void makea(char array[100]) is equivallent to void makea(char *array)
and void makea(char array[])
So sizeof(array) when applied inside the makea() is equivallent to
sizeof(char *).
array there is char *array.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
-------------------------------------------------------
This sf.net email is sponsored by: Dice - The leading online job board
for high-tech professionals. Search and apply for tech jobs today!
http://seeker.dice.com/seeker.epl?rel_code=31
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Ioannis V. <no...@ho...> - 2002-07-31 15:09:15
|
<http://run.to/noicys> -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Ramana Kumar Sent: Wednesday, July 31, 2002 3:36 PM To: Carlos Garc?a del Monte; C++ Subject: RE: [Dev-C++] sizeof array thank you carlos i had in fact thought of using a special array member at the end, and thank you for illustrating implentation of this so beautifully. i'm afraid this may have to be the way i do it in the end, unless i simply don't pass the array and declare it locally. Or use vector: #include <iostream> #include <vector> void f(std::vector<std::vector<int> >&array) { using namespace std; cout<<array.size()<<endl; } int main() { using namespace std; /// 2-dimensional 100x50 int array initialised to 0 vector<vector<int> >arr(100, vector<int>(50)); f(arr); } but since the array is in fact a two-dimensional array full of instances of my own String class, adding a "terminating character" will involve creating too much arbitrary code for my liking. I am still dreaming of the possibility of sizeof-ing the array with the built in operator, if anyone knows how to do this correctly. In fact, i am highly curious about the workings of the sizeof operator. I realize that since passing an array to a function is actually passing a pointer to the first object ( is this x[0] or x[0][0] in a multidimensional array?), x[0] and &x[0][0] the sizeof operator gets the size of that pointer... or does it? what are you passing the operator when the array is local? When the array is local and you pass the array's name you pass the array. A function can accept only a pointer to the first object or a reference, so in the function you pass the pointer variable (which points to the first element of the array). As a result you get the size of the pointer variable itself. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net <http://www.noicys.cjb.net/> * Alternative URL: http://run.to/noicys |
|
From: Carlos d. M. <cg...@wo...> - 2002-07-31 18:55:11
|
vectors, of course, but I understood vectors weren't an option, that Mr Ramana wants arrays. But I don't like them very much, I'll need something that you would say "vectors!", but I tried them in a elevator simulation, and I got problems with STL, if I used vector (or list, now I don't remember when it was vector and when list) I had a problem, I tried to do it with list but then the list couldn't do one pass at it should be done. So now I am writing my own container library, since what I need is something rather complicated, and if for that I got problems, for which I need... woooo!. Well, I haven't tested the mine in that simulation (now I've forget its details), but tests with another program work fine. So I say goodbye to STL, vector, list and so, and I'll make my own container classes, I hope much more powerful than STL. Out limits! My classes have (or will have sooner or later) all capabilities of STL and more. |
|
From: Ioannis V. <no...@ho...> - 2002-08-01 09:33:22
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Carlos Garc?a del Monte > Sent: Wednesday, July 31, 2002 9:51 PM > To: dev-cpp-users-list > Subject: Re to vectors: [Dev-C++] sizeof array > > > > vectors, of course, but I understood vectors weren't an > option, that Mr > Ramana wants arrays. > But I don't like them very much, I'll need something that you > would say > "vectors!", but I tried them in a elevator simulation, and I got > problems with STL, if I used vector (or list, now I don't > remember when > it was vector and when list) I had a problem, I tried to do > it with list > but then the list couldn't do one pass at it should be done. No insult intended, but 100% the problem was that you did not know how to use them and not the vector itself. > So now I am > writing my own container library, since what I need is > something rather > complicated, and if for that I got problems, for which I > need... woooo!. This is a radical step. Better learn what the standard library has to offer you and then try to make your stuff. :) The standard library is very wise, very generic and very high level. > Well, I haven't tested the mine in that simulation (now I've > forget its > details), but tests with another program work fine. So I say > goodbye to > STL, vector, list and so, and I'll make my own container > classes, I hope > much more powerful than STL. Out limits! You may be an excellent coder and write an excellent container, but i strongly suspect that there is no need for that. > My classes have (or will have sooner or later) all capabilities of STL > and more. :) Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |
|
From: Carlos d. M. <cg...@wo...> - 2002-08-01 11:07:38
|
Answers inline. Ioannis Vranos escribi=F3: > > -----Original Message----- > > From: dev...@li... > > [mailto:dev...@li...] On Behalf > > Of Carlos Garc?a del Monte > > Sent: Wednesday, July 31, 2002 9:51 PM > > To: dev-cpp-users-list > > Subject: Re to vectors: [Dev-C++] sizeof array > > > > > > > > vectors, of course, but I understood vectors weren't an > > option, that Mr > > Ramana wants arrays. > > But I don't like them very much, I'll need something that you > > would say > > "vectors!", but I tried them in a elevator simulation, and I got > > problems with STL, if I used vector (or list, now I don't > > remember when > > it was vector and when list) I had a problem, I tried to do > > it with list > > but then the list couldn't do one pass at it should be done. > > No insult intended, but 100% the problem was that you did not know how > to use them and not the vector itself. I don't see any insult. Of course this is a possibility I don't reject, b= ut if the code was wrogn I couldn't see any error (at lest clearly visible), and a coulpe of times in tiny experiments without possible error passing = my own objects, having included everything, I got that the object was not declared, or somethign similar, not declared vector<object, iterator> (th= is is not an exact cite, I don't remember exactly how was the message), and = it didn't accept a correct declaration of an iterator, (code just equal to t= he book, and which worked with other kinds of data). Sure I would make what I want with vectors, but I believe making my own containers will be easier than correct my use of them. However, I think t= hat there was a problem of one feature (I've forget what) that needed a capability of vectors, but another which has lists (or was at inverse). Perhaps there was no error in vectors or lists and the errors which sem related to them were consequence of another pair of strange errors: funct= ion called where no call was in the code, and calls to functions in other pla= ces where it was called. Perhaps a bad use of my objects with the vector, not with the vector itself. For example, people were objects of the vector, o= ne man enters, a man is created and added to the vector, when he does what h= ave to do, the vector's iterator goes to the next man, or starts the next cyc= le through men in the building, right, but when they pushed the elevator button, the destructor was called, and debugging I didn't see the program passing through a call to it!!! > > > > So now I am > > writing my own container library, since what I need is > > something rather > > complicated, and if for that I got problems, for which I > > need... woooo!. > > This is a radical step. Better learn what the standard library has to > offer you and then try to make your stuff. :) The standard library is > very wise, very generic and very high level. What I said is something about me, that I say perhaps is the case of othe= rs (or not). But for everyone who is reading this I must add that, naturally= , I don't recommend my solution if you are not completely decided to it, I of course recommend the yours: Learn to use STL!!!! > > > > Well, I haven't tested the mine in that simulation (now I've > > forget its > > details), but tests with another program work fine. So I say > > goodbye to > > STL, vector, list and so, and I'll make my own container > > classes, I hope > > much more powerful than STL. Out limits! > > You may be an excellent coder and write an excellent container, but i > strongly suspect that there is no need for that. > > > My classes have (or will have sooner or later) all capabilities of ST= L > > and more. > > :) > > Ioannis > > * Ioannis Vranos > * Programming pages: http://www.noicys.cjb.net > * Alternative URL: http://run.to/noicys > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
|
From: Ramana K. <ra...@my...> - 2002-08-01 08:56:58
|
Vectors would be great, except for the fact that i can't initialise them
using {...}
which is the only convenient way to do something like
{
"YOU'RE","YOU ARE",
"I'M","I AM",
}
and i have checked that vectors can't be initialised by passing them an
array.
so, i have three options remaining.
1. this is quite inelegant, but since arrays are initialised with {...}, can
i not pass a value in {} directly to the function so that the parameter is
treated as a local array within the function?
2. i assume this is not possible, but perhaps since the function receives a
pointer to the first element of a array, i can somehow dereference this to
get the whole array or something like that?
3. this is what i will have to do soon... just write the array locally
thanks for all your help so far
ramana
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Ioannis
Vranos
Sent: Thursday, 1 August 2002 1:09 AM
To: 'Ramana Kumar'; 'C++'
Subject: RE: [Dev-C++] sizeof array
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Ramana Kumar
Sent: Wednesday, July 31, 2002 3:36 PM
To: Carlos Garc?a del Monte; C++
Subject: RE: [Dev-C++] sizeof array
thank you carlos
i had in fact thought of using a special array member at the end, and thank
you for illustrating implentation of this so beautifully.
i'm afraid this may have to be the way i do it in the end, unless i simply
don't pass the array and declare it locally.
Or use vector:
#include <iostream>
#include <vector>
void f(std::vector<std::vector<int> >&array)
{
using namespace std;
cout<<array.size()<<endl;
}
int main()
{
using namespace std;
/// 2-dimensional 100x50 int array initialised to 0
vector<vector<int> >arr(100, vector<int>(50));
f(arr);
}
but since the array is in fact a two-dimensional array full of instances of
my own String class, adding a "terminating character" will involve creating
too much arbitrary code for my liking. I am still dreaming of the
possibility of sizeof-ing the array with the built in operator, if anyone
knows how to do this correctly. In fact, i am highly curious about the
workings of the sizeof operator. I realize that since passing an array to a
function is actually passing a pointer to the first object ( is this x[0] or
x[0][0] in a multidimensional array?),
x[0] and &x[0][0]
the sizeof operator gets the size of that pointer... or does it? what are
you passing the operator when the array is local?
When the array is local and you pass the array's name you pass the array. A
function can accept only a pointer to the first object or a reference, so in
the function you pass the pointer variable (which points to the first
element of the array). As a result you get the size of the pointer variable
itself.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|
|
From: Ioannis V. <no...@ho...> - 2002-08-01 10:02:07
|
> -----Original Message-----
> From: Ramana Kumar [mailto:ra...@my...]
> Sent: Thursday, August 01, 2002 11:57 AM
> To: Ioannis Vranos; C++
> Subject: RE: [Dev-C++] sizeof array
>
>
> Vectors would be great, except for the fact that i can't
> initialise them
> using {...}
> which is the only convenient way to do something like
> {
> "YOU'RE","YOU ARE",
> "I'M","I AM",
> }
> and i have checked that vectors can't be initialised by
> passing them an
> array.
Of course you can:
#include <vector>
#include <string>
int main()
{
using namespace std;
char temparray[4][20]={"YOU'RE","YOU ARE", "I'M","I AM"};
vector<string>array(&temparray[0], &temparray[4]);
}
> so, i have three options remaining.
> 1. this is quite inelegant, but since arrays are initialised
> with {...}, can
> i not pass a value in {} directly to the function so that the
> parameter is
> treated as a local array within the function?
You must understand something. Objects (including arrays) are passed by
reference only by using a pointer or reference. In the case of an built
in array it is a pointer or reference too its first element.
sizeof() does not see an array since an array is not passed, a variable
pointer pointing to the first element is passed. In case of C-style
strings you have not such a problem since there is '\0' and strlen().
But why mess with this C-style low level (and unecessary) stuff?
> 2. i assume this is not possible, but perhaps since the
> function receives a
> pointer to the first element of a array, i can somehow
> dereference this to
> get the whole array or something like that?
By dereferencing it you get the value of the pointed element (in your
example of the char).
> 3. this is what i will have to do soon... just write the array locally
> thanks for all your help so far
Or use standard library facilities. :)
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|
|
From: Carlos d. M. <cg...@wo...> - 2002-08-01 10:52:31
|
There is another way for doing things which does not need special
characters.
You need declare two pointers of the kind of the array data, when you
have the last member of the first row you store its direction in the
first pointer, and when you get the last member of the whole array you
store its location in the second pointer. Then you pass to the function
the pointer which defines the array, the first pointer and the second.
Then you declare three ints (of course the first pointer and the first
pointer are optional, see below). And you work with them:
If you want know the size of each row (considering all have the same
size or can be considered as if they have) you substract the array
pointer to the first pointer and sum the size of one element, and store
it in the first int, then you make the same substituting the first
pointer with the second, and store the result in the second int, so now
you have the size of the whole array, and finally you divide the second
int by the first, so you have the number of rows. If you have arrays of
more than two dimensions you need adapt it.
For example:
kind *array, *endrow, *whole;
for(rownum = 0; rownum<number-of.rows-you-need; rownum++){
for(rowmem=0; rowmem<number-of-members-for-each-row; rowmem++){
array[rownum][rowmem];
if(rownum ==0)
endrow = &array[rownum][rowmem];
whole = &array[rownum][rowmem];
}
}
rowsize = endrow - array + sizeof(kind);
wholesize = whole - array + sizeof(kind);
numofrows = wholesize / rowsize;
Of course, if you're interested only in the size of the whole array you
forget rowssize and endrow and if(rownum==0).
|
|
From: Ioannis V. <no...@ho...> - 2002-07-31 14:53:15
|
> -----Original Message----- > From: Ramana Kumar [mailto:ra...@my...] > Sent: Wednesday, July 31, 2002 2:19 PM > To: Ioannis Vranos; C++ > Subject: RE: [Dev-C++] sizeof array > > > thanks ioannis, i have briefly read your reply and it is what > i had feared. > is there any way to implement what i had before so that the > sizeof operator > reports the size as if it were a local array? for example, > can i pass the > array to the function by reference or dereference the pointer that is > passed? No there is no way for a built in array. The only thing you can do, is pass an additional argument, the size of the array in the style void f(char *s[], const unsigned long SIZE); Or better, use some standard library container, such as vector. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |