
May 23rd, 2006, 04:05 PM
| | | pointer argument trouble
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]);
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) | 
May 23rd, 2006, 04:25 PM
| | | Re: pointer argument trouble
"voidtwerp" <voidtwerp@gmail.com> skrev i en meddelelse
news:1148396593.949362.288260@i39g2000cwa.googlegr oups.com...[color=blue]
> 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[])[/color]
[color=blue]
> printf("Count %d: %d (%d)\r\n",i,coincount[i],count);[/color]
You might wanna read the the printf documentation.
Since this is C++ use std::cout instead
std::cout << "Count " << i << ": " << coincount[i] .... fill in rest
yourself.
For the prinf you use %d or %i is for signed decimal integer
%u is for unsigned decimal integer.. And i recall you type is
UINT (unsigned int)
//eric | 
May 23rd, 2006, 04:25 PM
| | | Re: pointer argument trouble
voidtwerp wrote:[color=blue]
> 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);[/color]
And what is the implemenatation of that function? Next time post it
because it might be relevant...
BTW, I can _guess_ what 'ulong' and 'uint' are, but you need to tell
us what it is. And, 'APIDLL_EXPORT' or '_cdecl' are also undefined
here.
[color=blue]
> }
>
> // my .cpp file
>
> void Help_ProductSale_CountCoins(uint coinvalue[],ulong coincount[])
> {
> ulong count;
> for(int i=6;i--;)
> {
> ENGINE_GetCoinCount(coinvalue[i],&coincount[i]);
> ENGINE_GetCoinCount(coinvalue[i],&count);
> printf("Count %d: %d (%d)\r\n",i,coincount[i],count);[/color]
If you want to print 'unsigned long' values, you need to add 'l' to the
format specification, IIRC.
[color=blue]
> }
> }
> 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)[/color]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask | 
May 23rd, 2006, 04:35 PM
| | | Re: pointer argument trouble
>> void Help_ProductSale_CountCoins(uint coinvalue[],ulong coincount[])[color=blue][color=green]
>> printf("Count %d: %d (%d)\r\n",i,coincount[i],count);[/color]
>
>You might wanna read the the printf documentation.
>Since this is C++ use std::cout instead
>
>std::cout << "Count " << i << ": " << coincount[i] .... fill in rest
>yourself.[/color]
unfortunately as I am using eVC++ this is not an option - however the
result I was showing stands even if I do change the format specifiers. | 
May 23rd, 2006, 04:55 PM
| | | Re: pointer argument trouble
>voidtwerp wrote:[color=blue][color=green]
>> Am I being really stupid here - I cant see what the problem is.[/color]
>[color=green]
>> 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).[/color]
>[color=green]
>> // 3rd party dll header file
>> extern "C" {
>> APIDLL_EXPORT bool _cdecl ENGINE_GetCoinCount(uint CoinValue,ulong*
>> cnt);[/color]
>
>And what is the implemenatation of that function? Next time post it
>because it might be relevant...[/color]
I dont have access to the dll code which includes implementation of the
above
[color=blue]
>
>BTW, I can _guess_ what 'ulong' and 'uint' are, but you need to tell
>us what it is. And, 'APIDLL_EXPORT' or '_cdecl' are also undefined
>here.[/color]
unsigned long, unsigned int, _declspec(dllexport) - I have a suspicion
that this is compiler specific as is _cdecl
maybe I need to take this to a compiler specific group rather than a
C++ one.
[color=blue]
>[color=green]
>> }[/color]
>[color=green]
>> // my .cpp file[/color]
>[color=green]
>> void Help_ProductSale_CountCoins(uint coinvalue[],ulong coincount[])
>> {
>> ulong count;
>> for(int i=6;i--;)
>> {
>> ENGINE_GetCoinCount(coinvalue[i],&coincount[i]);
>> ENGINE_GetCoinCount(coinvalue[i],&count);
>> printf("Count %d: %d (%d)\r\n",i,coincount[i],count);[/color]
>
>If you want to print 'unsigned long' values, you need to add 'l' to the
>format specification, IIRC.[/color]
the output results still stand when I change the format specifiers
[color=blue]
>
>- Hide quoted text -
>- Show quoted text -[color=green]
>> }
>> }
>> bool Test_ProductSale()
>> {
>> uint coinvalue[]={5,10,20,50,100,200};
>> ulong coinstart[6];
>> Help_ProductSale_CountCoins(coinvalue,coinstart);
>> }[/color]
>[color=green]
>> 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)[/color][/color] | 
May 23rd, 2006, 05:45 PM
| | | Re: pointer argument trouble
voidtwerp wrote:[color=blue][color=green]
>> voidtwerp wrote:[color=darkred]
>>> Am I being really stupid here - I cant see what the problem is.[/color]
>>[color=darkred]
>>> 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).[/color]
>>[color=darkred]
>>> // 3rd party dll header file
>>> extern "C" {
>>> APIDLL_EXPORT bool _cdecl ENGINE_GetCoinCount(uint CoinValue,ulong*
>>> cnt);[/color]
>>
>> And what is the implemenatation of that function? Next time post it
>> because it might be relevant...[/color]
>
> I dont have access to the dll code which includes implementation of
> the above[/color]
So it's part of your program but not part of Standard library and not
written by you, right? We can't help you with that.
[color=blue]
> [...][color=green][color=darkred]
>>> bool Test_ProductSale()
>>> {
>>> uint coinvalue[]={5,10,20,50,100,200};
>>> ulong coinstart[6];
>>> Help_ProductSale_CountCoins(coinvalue,coinstart);
>>> }[/color]
>>[color=darkred]
>>> 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)[/color][/color][/color]
It seems that the "ENGINE" you're using to count the coins has no
idea that coins with values of 5 or 20 exist. Could it be you're
using a setting with your "ENGINE" that only allow coins of some
specific nomination? As an example, in the USA accepted coins have
nominations of 1 cent, 5, 10, 25, 50 cents, and 1 dollar. There
is no coin with value 20 or with value 200 in the USA (IIRC).
So, RTFM for your "ENGINE". Your problem is not of the C++ nature.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask | 
May 23rd, 2006, 09:35 PM
| | | Re: pointer argument trouble
"voidtwerp" <voidtwerp@gmail.com> wrote in message
news:1148396593.949362.288260@i39g2000cwa.googlegr oups.com...[color=blue]
> 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]);[/color]
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.
[color=blue]
> 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)
>[/color] | 
May 23rd, 2006, 09:45 PM
| | | Re: pointer argument trouble
Jim Langston wrote:[color=blue]
> "voidtwerp" <voidtwerp@gmail.com> wrote in message
> news:1148396593.949362.288260@i39g2000cwa.googlegr oups.com...[color=green]
>> 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]);[/color]
>
> 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.[/color]
No. The condition (the second expression in the 'for' statement) has
been executed once at this point, so 'i' actually contains 5. You need
to pay attention to those things...
[color=blue]
> [..][/color]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask | 
May 23rd, 2006, 09:55 PM
| | | Re: pointer argument trouble
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:e4vrqn$mpj$1@news.datemas.de...[color=blue]
> Jim Langston wrote:[color=green]
>> "voidtwerp" <voidtwerp@gmail.com> wrote in message
>> news:1148396593.949362.288260@i39g2000cwa.googlegr oups.com...[color=darkred]
>>> 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]);[/color]
>>
>> 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.[/color]
>
> No. The condition (the second expression in the 'for' statement) has
> been executed once at this point, so 'i' actually contains 5. You need
> to pay attention to those things...[/color]
Gah, you're right. I actually thought of that before I replied, but then
realized that i-- was post and would be decremented after the statement, but
I was thinking the statement block instead of the for statement itself.
That's why I hate that type of code. | 
May 23rd, 2006, 11:15 PM
| | | Re: pointer argument trouble
Jim Langston wrote:[color=blue]
> "Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
> news:e4vrqn$mpj$1@news.datemas.de...[color=green]
> > Jim Langston wrote:[color=darkred]
> >> "voidtwerp" <voidtwerp@gmail.com> wrote in message
> >> news:1148396593.949362.288260@i39g2000cwa.googlegr oups.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.[/color]
> >
> > No. The condition (the second expression in the 'for' statement) has
> > been executed once at this point, so 'i' actually contains 5. You need
> > to pay attention to those things...[/color]
>
> Gah, you're right. I actually thought of that before I replied, but then
> realized that i-- was post and would be decremented after the statement, but
> I was thinking the statement block instead of the for statement itself.
> That's why I hate that type of code.[/color]
Yes, certainly a great way to obscure your intention. | 
May 24th, 2006, 10:45 AM
| | | Re: pointer argument trouble
>Jim Langston wrote:[color=blue][color=green]
>> "Victor Bazarov" <v.Abaza...@comAcast.net> wrote in message
>> news:e4vrqn$mpj$1@news.datemas.de...[color=darkred]
>> > Jim Langston wrote:
>> >> "voidtwerp" <voidtw...@gmail.com> wrote in message[/color][/color][/color]
[snip][color=blue][color=green][color=darkred]
>> >>> ulong count;
>> >>> for(int i=6;i--;)
>> >>> {
>> >>> ENGINE_GetCoinCount(coinvalue[i],&coincount[i]);[/color][/color][/color]
[snip][color=blue][color=green][color=darkred]
>> >> this array has 6 values. They are numbered from 0 to 5. Yet you are
>> >> looking at coinvalue[6] which is an array overflow.[/color][/color]
>[color=green][color=darkred]
>> > No. The condition (the second expression in the 'for' statement) has
>> > been executed once at this point, so 'i' actually contains 5. You need
>> > to pay attention to those things...[/color][/color][/color]
[snip][color=blue][color=green]
>> That's why I hate that type of code.[/color]
>
>Yes, certainly a great way to obscure your intention.[/color]
what would you suggest as the least obscure form of
for(int i=6;i--;) | 
May 24th, 2006, 10:55 AM
| | | Re: pointer argument trouble
* voidtwerp:[color=blue]
> for(int i=6;i--;)[/color]
for( int i = 5; i >= 0; --i )
This says exactly which values 'i' will have in the loop body, and
allows any starting value, as opposed to only start values >= 0.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? | 
May 24th, 2006, 11:35 AM
| | | Re: pointer argument trouble
>>> uint coinvalue[]={5,10,20,50,100,200};
[color=blue]
>It seems that the "ENGINE" you're using to count the coins has no
>idea that coins with values of 5 or 20 exist. Could it be you're
>using a setting with your "ENGINE" that only allow coins of some
>specific nomination? As an example, in the USA accepted coins have
>nominations of 1 cent, 5, 10, 25, 50 cents, and 1 dollar. There
>is no coin with value 20 or with value 200 in the USA (IIRC).[/color]
but there is in europe :)
[color=blue]
>So, RTFM for your "ENGINE". Your problem is not of the C++ nature.[/color]
TFM has been thoroughly read - though I am beginning to suspect the dll
implementation.
void Help_ProductSale_CountCoins(uint coinvalue[],ulong coincount[])
{
ulong count;
for(int i=6;i--;)
{
ENGINE_GetCoinCount(coinvalue[i],&coincount[i]);
ENGINE_GetCoinCount(coinvalue[i],&count);
printf("Count %d: %lu (%lu)\r\n",i,coincount[i],count);
}
}
what I am most concerned with at the moment is that the above code
snipped produces different values for coincount[i] and count - what
could be going on?
Count 5: 0 (0)
Count 4: 0 (0)
Count 3: 0 (0)
Count 2: 5 (0)
Count 1: 182 (0)
Count 0: 200815 (0) | 
May 24th, 2006, 01:55 PM
| | | Re: pointer argument trouble
voidtwerp wrote:[color=blue]
> [..]
> what I am most concerned with at the moment is that the above code
> snipped produces different values for coincount[i] and count - what
> could be going on?
>
> Count 5: 0 (0)
> Count 4: 0 (0)
> Count 3: 0 (0)
> Count 2: 5 (0)
> Count 1: 182 (0)
> Count 0: 200815 (0)[/color]
Who the F knows? Contact the vendor of your "ENGINE".
V
P.S. This is another wild guess, but check that you initialise your
"ENGINE" correctly. See if TFM contains a "reset the counts" kind of
operation, and see if it needs to be performed.
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 205,338 network members.
|