Re: Aaahhrg! Trouble passing an array of structs to a function!
- From: Robby <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 16 Mar 2009 12:46:19 -0700
Hello Igor,
aoooooh ! yup! I moved the function declaration up and it worked. When I
post small examples like this I tend to forget that the function is not
declared in a header as its usually done. And that's what got me today!
Why would you ever want to do such a thing?
Because I will eventually have many types of arrays of structures but want
to use the functionality of that one same function for all of them to carry
out some predefined logic and/or member variable updating. By the tone of
your question, I guess you are imposing that the way I am going about this
isn't right.
For example, if I have say 20 different types of arrays of structures and a
particular member of every strcture needs to be tested, updated or
manipulated always using a specific logic, what should one do. Create 20
different functions... one for each array of structures ? In my humble
opinion that would appear to be redundant. Because what would happen if 20
turns to 40, 100 or even 500? So I don't know any other approach to this
scenario but to try to do what I am doing here.
By the way, thankyou for your help! Much appreciated everytime.
--
Best regards
Roberto
"Igor Tandetnik" wrote:
"Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message.
news:B5BFB9A6-398D-4971-AFC0-9FDA1BAFBD64@xxxxxxxxxxxxx
F1()
{
F3(pc);
//F3(mn); << I may have to pass a different array to same function
parameter }
void F3(PC pc[])
{ <<<< error here! ????
int x;
}
I get the following error in the line in above snippet:
c:\dts_visual_c++\test1\test1\test1.c(44) : error C2371: 'F3' :
redefinition; different basic types
Declare the function before calling it.
A C++ compiler would have produced an error, but a C compiler allows
calling an undeclared function, and guesses at the function signature
based on the call. Then it complains when the actual function definition
doesn't match its lucky guess.
Also, what if I would require to pass more than one array of
structures type via a single function parameter?????
Why would you ever want to do such a thing?
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
- Follow-Ups:
- Re: Aaahhrg! Trouble passing an array of structs to a function!
- From: Scott McPhillips [MVP]
- Re: Aaahhrg! Trouble passing an array of structs to a function!
- From: Igor Tandetnik
- Re: Aaahhrg! Trouble passing an array of structs to a function!
- References:
- Aaahhrg! Trouble passing an array of structs to a function!
- From: Robby
- Re: Aaahhrg! Trouble passing an array of structs to a function!
- From: Igor Tandetnik
- Aaahhrg! Trouble passing an array of structs to a function!
- Prev by Date: Re: Aaahhrg! Trouble passing an array of structs to a function!
- Next by Date: Re: Errors C3859 and C1076
- Previous by thread: Re: Aaahhrg! Trouble passing an array of structs to a function!
- Next by thread: Re: Aaahhrg! Trouble passing an array of structs to a function!
- Index(es):
Relevant Pages
|