473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 23 '06 #1
13 1594

"voidtwerp" <vo*******@gmail.com> skrev i en meddelelse
news:11**********************@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[]) printf("Count %d: %d (%d)\r\n",i,coincount[i],count);


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 23 '06 #2
voidtwerp wrote:
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);
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.
}

// 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);
If you want to print 'unsigned long' values, you need to add 'l' to the
format specification, IIRC.
}
}
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)


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 23 '06 #3
>> void Help_ProductSale_CountCoins(uint coinvalue[],ulong coincount[])
printf("Count %d: %d (%d)\r\n",i,coincount[i],count);


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.


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 23 '06 #4
>voidtwerp wrote:
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);


And what is the implemenatation of that function? Next time post it
because it might be relevant...


I dont have access to the dll code which includes implementation of the
above

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.
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.
}
// 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);


If you want to print 'unsigned long' values, you need to add 'l' to the
format specification, IIRC.


the output results still stand when I change the format specifiers

- Hide quoted text -
- Show quoted text -
}
}
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 23 '06 #5
voidtwerp wrote:
voidtwerp wrote:
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);


And what is the implemenatation of that function? Next time post it
because it might be relevant...


I dont have access to the dll code which includes implementation of
the above


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.
[...]
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)


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 23 '06 #6

"voidtwerp" <vo*******@gmail.com> wrote in message
news:11**********************@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.

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)

May 23 '06 #7
Jim Langston wrote:
"voidtwerp" <vo*******@gmail.com> wrote in message
news:11**********************@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.


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...
[..]


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 23 '06 #8

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:e4**********@news.datemas.de...
Jim Langston wrote:
"voidtwerp" <vo*******@gmail.com> wrote in message
news:11**********************@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.


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...


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 23 '06 #9

Jim Langston wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:e4**********@news.datemas.de...
Jim Langston wrote:
"voidtwerp" <vo*******@gmail.com> wrote in message
news:11**********************@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.


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...


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.


Yes, certainly a great way to obscure your intention.

May 23 '06 #10
>Jim Langston wrote:
"Victor Bazarov" <v.Abaza...@comAcast.net> wrote in message
news:e4**********@news.datemas.de...
> Jim Langston wrote:
>> "voidtwerp" <voidtw...@gmail.com> wrote in message [snip] >>> ulong count;
>>> for(int i=6;i--;)
>>> {
>>> ENGINE_GetCoinCount(coinvalue[i],&coincount[i]); [snip] >> this array has 6 values. They are numbered from 0 to 5. Yet you are
>> looking at coinvalue[6] which is an array overflow. > 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...
[snip] That's why I hate that type of code.


Yes, certainly a great way to obscure your intention.


what would you suggest as the least obscure form of
for(int i=6;i--;)

May 24 '06 #11
* voidtwerp:
for(int i=6;i--;)


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 24 '06 #12
>>> uint coinvalue[]={5,10,20,50,100,200};
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).
but there is in europe :)
So, RTFM for your "ENGINE". Your problem is not of the C++ nature.


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 24 '06 #13
voidtwerp wrote:
[..]
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)


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
May 24 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Thomas Barth | last post by:
Hi, I dont understand the third argument of this function. This function expect the address of a function, but what does "void *(*funktion)(void *)," mean? I am confused by so many "wildcards" :-)...
52
by: Douglas Garstang | last post by:
I can't believe I've been trying to work this out for hours now, and I can't believe I couldn't find someone asking for a similar solution in the newsgroups. No wonder I hate C so much, and every...
16
by: fix | last post by:
Hi all, I am new to C and I just started to program for a homework. I included my code down there. It is a fraction "class". I declared the Fraction struct, tried to create some invalid fraction,...
9
by: Juggernaut | last post by:
I am trying to create a p_thread pthread_create(&threads, &attr, Teste, (void *)var); where var is a char variable. But this doesnt't work, I get this message: test.c:58: warning: cast to pointer...
3
by: benjamin sago | last post by:
Hello all. I am writing a command shell, but am having trouble with memory allocations. I am trying to tokenise a string into a **char array for execvp (the unix launch-this-program function), but...
49
by: elmar | last post by:
Hi Clers, If I look at my ~200000 lines of C code programmed over the past 15 years, there is one annoying thing in this smart language, which somehow reduces the 'beauty' of the source code...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
8
by: toton | last post by:
HI, One more small doubt from today's mail. I have certain function which returns a pointer (sometimes a const pointer from a const member function). And certain member function needs reference...
27
by: rocco.rossi | last post by:
I've been trying to write a function capable of checking if a pointer value is set to NULL, and if it isn't, of deallocating and setting it's value to NULL regardless of the pointer's type. I...
7
by: ghulands | last post by:
I am having trouble implementing some function pointer stuff in c++ An object can register itself for many events void addEventListener(CFObject *target, CFEventHandler callback, uint8_t...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.