Re: pointer argument trouble
"voidtwerp" <voidtwerp@gmail.com> wrote in message
news:1148396593.949362.288260@i39g2000cwa.googlegroups.com...
Am I being really stupid here - I cant see what the problem is.
how can I be getting different values in coincount[i] and count? (note
that I dont think either is correct but I cannot be sure at this
stage).
// 3rd party dll header file
extern "C" {
APIDLL_EXPORT bool _cdecl ENGINE_GetCoinCount(uint CoinValue,ulong*
cnt);
}
// my .cpp file
void Help_ProductSale_CountCoins(uint coinvalue[],ulong coincount[])
{
ulong count;
for(int i=6;i--;)
{
ENGINE_GetCoinCount(coinvalue[i],&coincount[i]);
Warning: you passed coinvalue which was declared in Test_ProductSale as:
uint coinvalue[]={5,10,20,50,100,200};
this array has 6 values. They are numbered from 0 to 5. Yet you are
looking at coinvalue[6] which is an array overflow.
coincount was declared as:
ulong coinstart[6];
again, numbered 0 to 5, yet you are looking at [6], another array overflow.
I'm not sure if this is your problem, but it sure in the heck doesn't help.
Undefined behavior and all.
ENGINE_GetCoinCount(coinvalue[i],&count);
printf("Count %d: %d (%d)\r\n",i,coincount[i],count);
}
}
bool Test_ProductSale()
{
uint coinvalue[]={5,10,20,50,100,200};
ulong coinstart[6];
Help_ProductSale_CountCoins(coinvalue,coinstart);
}
output:
Count 5: 0 (0)
Count 4: 0 (0)
Count 3: 0 (0)
Count 2: 235138746 (0)
Count 1: 5 (0)
Count 0: 60597997 (0)