I’ve been looking at the Codility tests, (http://codility.com/) as I was thinking of trying to obtain a certificate, but I’ve come up against some very strange syntax errors, it’s seems to use a slightly different version of Objective-C to iOS.
For example, the function to complete was declared as so:
int equi (NSMutableArray *A) { //.... }
as opposed to
-(int)equi:(NSMutableArray *)A { //... }
and when I declared the following for loop (A is an array of NSNumber):
12. for (int i = 0; i < [A count]; i++){
13. total = total + [[A objectAtIndex:i] intValue];
14. }
it gave me the following compile errors:
func.m:12: error: 'for' loop initial declarations are only allowed in C99 mode
func.m:12: note: use option -std=c99 or -std=gnu99 to compile your code
func.m:13: error: invalid operands to binary + (have 'double' and 'id')
If anyone could shed any light on this, pre haps the version of objective-c or compiler version is different?
Thanks
EDIT: @Kos from Codility has commented below, they have recently switched their Objective-C compiler to Clang, which should mean most of the questions I’d asked are now non-issues.
Please note this question was strictly in the context of Codility, which does not explicitly tell you which version of C it is compiling against.
As H2CO3 pointed out, the declaration is a C-function. I was thrown because the test was supposed to be in Objective-C, not C, and while yes, Objective-C is a superset of C, I was expecting Objective-C syntax.
Codility does not give you access to compiler flags, hence why the stack trace was not useful. The problem was the initial declaration of
ibeing inside theforloop declaration (C90 style). It should have be rewritten as this to be explicit: