0

I have a function as follows:

-(int)ladderCalc:(NSArray*)amounts percentages:(NSArray*)percentages amount:(int)amount
{

   // Do some stuff

   return foo;
}

I have declared like this in the header file:

-(int)ladderCalc:(NSArray*)amounts percentages:(NSArray*)percentages amount:(int)amount;

But I am getting an error "implicit declaration of function is invalid in c99" when I try to use the int value returned elsewhere in the same file. Am I not declaring the function correctly?

UPDATE

I am realizing that I am not declaring this in the standardized way, I changed my declaration to MarkGranoff's recommendation (see the changes above) but I am still getting it as a warning this time.

Here is the context of how I am calling this function:

-(int)fooTotal: (int)amount 
{

   int totalFee = 0;

   // Declare arguments
   NSArray *percentages = [[NSArray alloc] initWithObjects:firstValue, secondValue, thirdValue, fourthValue, fifthValue, nil];
   NSArray *amounts = [[NSArray alloc] initWithObjects:sixthValue, seventhValue, eigthValue, ninthValue, nil];

   totalFee = ladderCalc(amounts,percentages,amount);

   return totalFee;
}

So, I am still getting a warning even though this seems to make sense as far as Obj-C style is concerned.

I am pretty sure I am not calling this function correctly, I am getting an unrecognized symbol error when I compile the project.

Undefined symbols for architecture i386:
  "_ladderCalc", referenced from:
      -[FeeCalcLibrary getMFModelTotal:] in FeeCalcLibrary-A83D2A7637F57664.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
5
  • 2
    Your code has non-idiomatic spacing and no parameter names - what's up with that? Commented Nov 16, 2011 at 21:53
  • your definition looks weird... It should be like - (int) ladderCalc: (NSArray )array1 amounts:(NSArray)amounts percentages:(NSArray *)percentages amount:(int)amount; Commented Nov 16, 2011 at 21:53
  • I agree with the other responders that your code looks weird and that this style is generally agreed to be a bad idea in Objective-C. However, from what I can see for declaration looks valid. To determine why you are getting the error, you should probably edit your post to include the code you use to call this method. Commented Nov 16, 2011 at 22:08
  • @TimDean I updated my question to provide context for calling it. I also tried the first answer below and am still getting a warning. Not sure why. Commented Nov 16, 2011 at 22:26
  • I think I am calling this function incorrectly in the bottom code snippet of my question. Should it be done using the square bracket messaging syntax? Commented Nov 16, 2011 at 22:41

2 Answers 2

2

Try this instead:

-(int)ladderCalc:(NSArray*)amounts percentages:(NSArray*)percentages amount:(int)amount;

and change the signature of the implementation to match. Then you have arguments with names you can reference in the code of the method. Namely: amounts, percentages, and amount.

Sign up to request clarification or add additional context in comments.

2 Comments

I think my problem is that I am calling it incorrectly in my code, what is the proper format for calling it?
Something like [myObject adderCalc:theAmounts percentages:thePtgs amount:amt].
0

As @MarkGranoff says.

Objective-C has it's arguments interspersed in the method name.

For the method declaration:

-(int)ladderCalcWithAmounts:(NSArray*)amounts percentages:(NSArray*)percentages amount:(int)amount;

the method name is (the colons are part of the name):

ladderCalc:percentages:amount:

Interspersed in the method name the arguments are:

(NSArray*)amounts
(NSArray*)percentages
(int)amount;

This improved readability over a "C" function call which might be:

int ladderCalcPercentagesAmount(NSArray *amounts, NSArray *percentages, amount);

Technically, Objective-C does not have named parameters, rather interspersed parameters. Named parameters tends to imply that position is not important just the associated names, an example are Python's named parameters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.