Re: Aaahhrg! Trouble passing an array of structs to a function!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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



.



Relevant Pages

  • Re: Origin of size_t? Curious.
    ... >>> If the size cannot be taken, then how can sizeof do ... >> contains a declaration of type that is too large, ... > My compiler accepts the oversized declaration, ... Several such arrays ...
    (comp.lang.c)
  • Re: anonymous initializer problem
    ... the declaration section (via initializer). ... and has only one public constructor that takes an array of field objects. ... This way I could define my dictionary in the declaration section where it is ... costructor declare custom static arrays that use the dictionary values, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Invalid conversion from char tp char*
    ... Consider using std::strings instead of char arrays. ... search as much for the declaration of an object. ... The problem is that array sizes must be compile-time constants. ... You should also prefer standard containers to arrays. ...
    (comp.lang.cpp)
  • Re: why is it comming
    ... > we all know in static allocation first of all we have to specify the ... >declaration of spaces in arrays then how did the foll. ...
    (comp.lang.c)
  • Re: strlen
    ... I am trying to get an understanding on strlen. ... Your problem is actually with the array declaration. ... arrays must have a constant dimension. ...
    (comp.lang.c)