Page 1 of 1

Problem with char[] and memset

PostPosted: Mon Jun 15, 2009 6:45 am
by skydereign
This could be just a problem with my setup, though I was able to replicate it in a simple version. I want to clear an array, to be specific a char[]. To clear an array, you use memset, neh?
Code: Select all
memset(myarray, 0, sizeof(myarray));

This should reset myarray, no matter what dimensions. The problem does not seem to be oriented in dimension, and actually it does set the subs to 0, setting it to null. It seems gameEditor or just some part of my code keeps the chars within the array alive. I found this not using text and strcpy, but I used this to show the problem in a simple setup, meaning it is not due to the text. In this, the actor moves and shows text, which does not make sense knowing how I set it up. For some reason, the char[] maintains its text whilst being NULL, so it is NULL and has text... Is this an error on my part, or is something else happening?

Re: Problem with char[] and memset

PostPosted: Mon Jun 15, 2009 12:21 pm
by makslane
Is better use:
memset(myarray, 0, n1*n2*sizeof(arraytype));


Where n1, n2, ... are the dimentions of your array, and arraytype is the type of elements (int, double, ...)

Re: Problem with char[] and memset

PostPosted: Mon Jun 15, 2009 7:01 pm
by skydereign
They end up being the same thing, as that is what sizeof shows. If I didn't know what the variable I was memseting, it may have had an effect, but since I know, it doesn't really matter, but I guess good habits are good to have. Though that does not change the outcome. It still seems to be caught in the dual state... Sorry, I forgot to attach the example.

Re: Problem with char[] and memset

PostPosted: Mon Jun 15, 2009 11:18 pm
by makslane
Ops! It is a ugly bug in the memset function used by Game Editor.
The menset with 0 value doesn't works :oops:

Re: Problem with char[] and memset

PostPosted: Tue Jun 16, 2009 5:35 am
by skydereign
A bug in the actual function? How does that work, did you rewrite parts of the language for gE, or what? Well, I developed a substitute function that does work, though it is slightly limited, but easily adaptable. I am going to post it on another more easily found thread.

Re: Problem with char[] and memset

PostPosted: Tue Jun 16, 2009 12:09 pm
by makslane
The current Game Editor uses the EiC library to parser and execute the C scripts.
To make the scripts safe and avoid crashs, the EiC rewrite the standard C functions, like memset!