[gameprogrammer] Re: VC++ array woes.
- From: "Jason Clark" <jclark@xxxxxxxx>
- To: <gameprogrammer@xxxxxxxxxxxxx>
- Date: Wed, 25 Aug 2004 08:23:10 -0600
Thanks to everyone who replied.
I think I have a more heinous problem. I have a hash define that is
getting printed with different values at different points in my program,
so something is definitely wrong!
I apologize for sending the messed up memset, I should have double
checked before sending it.
As far as the (NULL =3D=3D ....), that is a trick I learned from an old
timer and it's stuck with me. It's great for newbies and people, like
me, that race through there code. By putting the value compared against
on the left, if I mistype my comparative '=3D=3D' as an assignment =
operator
'=3D', the compiler will give me an lvalue warning and save me from
shooting myself in the foot.
i.e.,
if (3 =3D=3D myVar) ... vs if (myVar =3D 3)
A cool little trick I think.
Thanks again everyone, I am going to install VC++ on a different machine
and see if it's my hardware or the program.
Jason.
> -----Original Message-----
> From: gameprogrammer-bounce@xxxxxxxxxxxxx [mailto:gameprogrammer-
> bounce@xxxxxxxxxxxxx] On Behalf Of Jason Clark
> Sent: Monday, August 23, 2004 10:51 PM
> To: gameprogrammer@xxxxxxxxxxxxx
> Subject: [gameprogrammer] VC++ array woes.
>=20
> I=92m working on a randomly generated fractal map, and keep having the
> strangest problem. I finally narrowed it down to the data in the
arrays,
> not being what I expect.
> If I use memset or even manually go through the array (int**) and set
> the values to 0, not all get set, particularly the first two indexs
are
> not zeroed on the first pass.
> If I go through and memset or manually set to 0 again, then they will
> actually be zero.
> Has anyone ever heard of this type of error?
>=20
> I verified and reverified that this was the behavior, by removing
either
> the first zeroing loop or the second and end with the same results.
> I also copied the following code snippet onto a Linux machine and used
> gcc to compile it, but that had no errors.
>=20
> Thanks,
> Jason.
>=20
>=20
> Code snippet:
>=20
> // create the int* first
> if (NULL =3D=3D (tmp =3D malloc(sizeof(int*) * size))) {
> perror("Failed to allocate memory for int**");
> return (int**)NULL;
> }
> // Go through and create the actual ints
> for (iterations =3D 0;iterations < size;++iterations) {
> // malloc memory
> if (NULL =3D=3D (tmp[iterations] =3D
> malloc(sizeof(int*) * size))) {
> perror("Failed to allocate memory
> for int*");
> return (int**)NULL;
> }
> // zero out new array
> //memset(tmp[iterations],size,sizeof(int));
> }
> fprintf(glob->fd,"Checking viability of memset:\n");
> for (newy =3D 0;newy< size;++newy) {
> for (newx =3D 0;newx< size;++newx) {
> if (tmp[newy][newx] !=3D 0)
>=20
> fprintf(glob->fd,"tmp[%i][%i]=3D%i\n",newy,newx,tmp[newy][newx]);
> }
> }
> for (newy =3D 0;newy< size;++newy) {
> for (newx =3D 0;newx< size;++newx) {
> tmp[newy][newx]=3D0;
> }
> }
> fprintf(glob->fd,"Checking viability of manual 0ing:\n");
> for (newy =3D 0;newy< size;++newy) {
> for (newx =3D 0;newx< size;++newx) {
> if (tmp[newy][newx] !=3D 0)
>=20
> fprintf(glob->fd,"tmp[%i][%i]=3D%i\n",newy,newx,tmp[newy][newx]);
> }
> }
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.742 / Virus Database: 495 - Release Date: 8/19/2004
>=20
>=20
>=20
>=20
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>=20
>=20
>=20
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.742 / Virus Database: 495 - Release Date: 8/19/2004
>=20
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.742 / Virus Database: 495 - Release Date: 8/19/2004
=20
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: VC++ array woes.
- From: Dave Slutzkin
- References:
- [gameprogrammer] VC++ array woes.
- From: Jason Clark
Other related posts:
- » [gameprogrammer] VC++ array woes.
- » [gameprogrammer] Re: VC++ array woes.
- » [gameprogrammer] Re: VC++ array woes.
- » [gameprogrammer] Re: VC++ array woes.
- » [gameprogrammer] Re: VC++ array woes.
- » [gameprogrammer] Re: VC++ array woes.
- [gameprogrammer] Re: VC++ array woes.
- From: Dave Slutzkin
- [gameprogrammer] VC++ array woes.
- From: Jason Clark