Re: [Dev-C++] Number of elements of a multidimensional
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2002-11-28 18:08:43
|
Not true that sizeof never returns size of array. It depends on what
declaration the compiler sees when processing the sizeof operator.
void func(int *array) {
// sizeof(array) =3D sizeof(int*)
}
void func(int array[]) {
// sizeof(array) =3D sizeof(int*)
}
void func() {
int array[4];
// sizeof(array) =3D 4*sizeof(int)
}
Big gotcha about this.
char buf[100];
write(fd,buf,sizeof(buf));
converted to:
char *buf =3D malloc(100);
write(fd,buf,sizeof(buf))
would fail miserably, because the second version would only write 4 bytes
in a 32-bit machine...
/Per W
On Thu, 28 Nov 2002, Carlos Garc=EDa del Monte wrote:
> The sizeof applied to a array will give you the size of a pointer, never
> the size of the array.
> Say char *array; or char array[];
> Then sizeof(array) =3D 4. (at least in my intelIII x86, with win2k 4 is
> the size for any kind of pointer).
>=20
> The only solution is to have some special value for the end of the
> array. Which for strings is '\0', and you can try to set another
> depending on which kind of data you're working with and which range of
> values you can find, so you can then choose on of the values which are
> out of the range to set as that special value. So you can reach for it
> and you can then now, with the approppriate functions you can write the
> total size of the array and the size of each row of the multidimensional
> array.
>=20
> Samuel Keding escribi=F3:
>=20
> > Isn't there a keyword sizeof in C/C++? It seems like I
> > remember one but I've never had to use it. I think
> > there is one and I think it returns the number of
> > bytes in the array of objects. All you would have to
> > do is divide by the number of bytes that is in just
> > one object. I may be off on this. Like I said, I
> > haven't really had to use this before.
> >
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> > http://mailplus.yahoo.com
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: Get the new Palm Tungsten T
> > handheld. Power & Color in a compact size!
> > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
> > _______________________________________________
> > 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
>=20
>=20
>=20
> -------------------------------------------------------
> This SF.net email is sponsored by: Get the new Palm Tungsten T
> handheld. Power & Color in a compact size!
> http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
> _______________________________________________
> 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
>=20
|