PDA

View Full Version : Argument type 'void' is incomplete




markdaraju
Sep 20, 2012, 08:44 PM
Hi all,

I have just been asked to take ownership of iOS code of one of our company's apps.
It was quite a struggle to get the code to build on my machine (OSX 10.8, Xcode4.5 and simulator 5.1/6.0) but now most of the errors have been resolved except for this one that says "Argument type 'void' is incomplete"

The line that it's pointing at is

"
for(int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++){
---------->> [output appendFormat:@"%02x", macOut.mutableBytes[i]];
}
"

Apparently , there is something wrong with variable macOut. Following is the declaration of macOut :

" NSMutableData *macOut = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH];

CC_SHA256(dataIn.bytes, dataIn.length, macOut.mutableBytes);

NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];
"

I can't see anything missing but again, I am not very experienced in iOS programming. Appreciate if you can provide any pointers on resolving this .

Thanks,
Mark



ArtOfWarfare
Sep 21, 2012, 12:38 AM
Two declarations I'd like to see the code for:

1 - appendFormat:
2 - mutableBytes[]

Oh, and have you tried dereferencing mutableBytes[i]? Maybe *macOut.mutableBytes[i] will work better...? mutableBytes[] could just be an array of pointers pointing to the actual values, thus they'd need dereferencing to be used, right? I'm not quite sure why you'd get the error that you're getting, though...

Edit: Nevermind. mutableBytes is a standard NSMutableData ivar...

2X Edit: mutableBytes is a void*. Dereferencing it (by using [i]) will give you a void. So shouldn't you cast it to an int before you try printing it?

chown33
Sep 21, 2012, 01:04 AM
2X Edit: mutableBytes is a void*. Dereferencing it (by using [i]) will give you a void. So shouldn't you cast it to an int before you try printing it?

I'm pretty sure the goal of the posted code is to step through the bytes of the NSMutableData (note how i steps), formatting each byte as hex (%02x) as it's appended to a string (appendFormat:).

Unfortunately, the returned type is void*, not uint8_t* (see the standard C header stdint.h). Which should suggest a solution if one knows basic C. It's not even specific to iOS programming or Objective-C, just basic C skills.

markdaraju
Sep 21, 2012, 06:04 PM
The confusing part is this apparently compiled fine in 10.7 + Xcode 4.3 that the previos developers had used. They are no longer available for comments hence the conundrum. In the meantime I have tried a few different approaches such as type casting and using temp variables etc. but none of that seem to be helping.


Any other ideas ? I understand that I might be making very basic mistakes here but I do intend to learn as much as I can in the process.

Thanks for your responses!

chown33
Sep 21, 2012, 06:21 PM
The confusing part is this apparently compiled fine in 10.7 + Xcode 4.3 that the previos developers had used.

Honestly, I find that hard to believe. When I look up that method in older reference docs, it has always returned (void*). And ever since the 'void' type was created, it's been illegal to dereference a pointer to that type. So unless there was a compiler bug that somehow allowed it, or the declared return-type somehow changed for a brief period, I see no way it could ever work as given.


In the meantime I have tried a few different approaches such as type casting and using temp variables etc. but none of that seem to be helping.

When posting code, it's better to copy and paste actual text. It's much easier to work with than pictures of text.

As given in the picture, your type-cast is completely wrong. You need to cast the pointer before it's subscripted. You also need to cast it to the correct type, an unsigned byte, otherwise you won't be converting the bytes of the data, you'll be converting the bytes-interpreted-as-ints. A suitable temp variable of the correct type would also work:
uint8_t * theBytes = [macOut mutableBytes];
for(int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++){
[output appendFormat:@"%02x", theBytes[i]];
}

As I said before, it's basic C.