Re: Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code



<usman911@xxxxxxxxx> schrieb im Newsbeitrag
news:1140767196.913142.102800@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//goal: to make a 2 dimentional dynamic array and use it in matrix
multiplication plz help me, //i am using VC++
#include<iostream.h>
class Matrix
{
private:
int *e;
int m,n,sz;
static char count;
char name;
public:
Matrix(int mx = 0,int nx = 0):m(mx),n(nx)
{
sz = m*n;
e = new int[sz];
for(int i = 0;i<sz;i++) //initiaklize d array elements to 0
e[i] = 0;
count++;
name = count; //to have a naming convention of objects, etc A,B,C
}



void insert (int i,int j,int v) //to insert an element in the 2D array
{

if(i<=m && j<=n) //check is refference is ok then insert the item.
e[i * n + j] = v; //convert 2D indexes to one dimention.
else
cout<<"order violation, the matrix has order:"<<m<<'x'<<n<<endl;
}
[...]

Either your test or your conversion is wrong. Which one, depends on what
input you are expecting.

If your indexes should be in a range of [1:m] or [1:n] you should use '(i -
1) * n + j -1' to get the offset of that field in your array, and you should
also check, that no negative values or 0 are passed as indexes.

If your indexes should start at 0 as is common in C and C++, the conversion
is ok, but you must check that indexes are non-negative and less than, but
not equal to, m or n.

Of cause you have to fix those bugs everywhere. Write a little function that
converts coordinates into an offset and throws some exception if
coordinates are not valid.

HTH
Heinz


.



Relevant Pages

  • Re: typedef function with void parameters
    ... void pointer. ... | int foo ... data pointer type, but you need to know what the other type is ... in order to choose the proper conversion. ...
    (comp.lang.c)
  • Re: void pointer cast segfaults
    ... > I am trying to understand the behavior of void pointers. ... The (int *) cast is unnecessary. ... resulting pointer is not suitably aligned for an int. ... The conversion of an int to a void * is implementation defined. ...
    (comp.lang.c)
  • Re: comparison between signed and unsigned int
    ... snip ... ... unsigned int a = 5; ... The conversion results in UINT_MAX, ... Get rid of the 'void main', ...
    (comp.lang.c)
  • Re: Faster way to write in a file
    ... void convert ... int main ... converted output fast enough, will the resulting data ever be read by ... that needs decimal input, then the conversion has to happen some time, ...
    (comp.lang.c)
  • fluff.c - a kernel/driver/app scanning utility
    ... message strings that have no performance bearing what so ever. ... alignment of text strings that are porking up the binary image. ... static char *ScanForZero ... static int StrCheck ...
    (Linux-Kernel)