-2

Sorry for my newbie question. Please refrain from down voting me because I am learning C. I am an experienced programmer on other languages, but not on C. I am trying to learn C at the same time I am trying to understand a library for iOS called Novaine, on Github.

This library has a module with the following signature:

Novocaine *audioManager = [Novocaine audioManager];

[audioManager setInputBlock:^(float *newAudio, UInt32 numSamples, UInt32 numChannels) {

}];

So, the internal block is receiving numSamples, numChannels and newAudio and newAudio is of kind float pointer?

What kind of object is this? an array of floats? if this is an array, how do I access its values? How do I know the number of elements it has?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
John Doe
  • 93
  • 7
  • 2
    I understand you're learning [tag:c], but, this is not [tag:c] code. It's [tag:objective-c] and it's a completely different thing. You should start by learning the difference perhaps. What you ask can be answered by a [tag:c] programmer too, but it's way to broad for SO. As I see it, if you don't know what pointers are, you should "*refrain*" from writing code by the time being, and search for a good resource to read about pointers. SO Also, does not provide information about that so GOOGLE it. – Iharob Al Asimi Dec 13 '15 at 19:56
  • possible duplicate of [Sizes of arrays declared with pointers](http://stackoverflow.com/q/18414310) – jscs Dec 13 '15 at 20:26
  • @JohnDoe that's pointer to float. It's meaning is defined by that drug library, just find source of `setInputBlock` method there. – c-smile Dec 13 '15 at 20:48
  • 1
    @JohnDoe I am sorry, it was not my intention. And I am even more sorry, because [you are apparently wrong](http://www.drdobbs.com/mobile/pointers-in-objective-c/225700236). You should be patient when asking here. I was trying to point out that you need to understand some basics before trying more advanced things. Again sorry to offend you. Also, you tagged with [tag:ios] and other tags related to [tag:objective-c] really. And This code is NOT [tag:c]. And I hope my level of the useless kindness that you want is 0. – Iharob Al Asimi Dec 13 '15 at 22:43

1 Answers1

-1

This is a pointer to float value. Nothing strange here. It is often use to point some area in memory. You don't know the size of this are. Might be a single float but also can be larger, continuous space in memory.

You don't know what type of object is stored there. float doesn't mean that floats are stored there. It could be declared as void * as well. Again, it is just a space in memory. By typing float * you just give the compile a hint that when you move newAudio pointer (doing or example newAudio ++) it will move a pointer by a sizeof(float) number of bytes.

Based on method fingerprint I assume that this is a pointer to the first element of some buffer which size is probably numSamples * numChannels * size of single sample

This part of memory should be allocated first, to make sure that it's reserved for you:

float *newAudio = calloc(numSamples * numChannels, sizeof(float));

psci
  • 903
  • 9
  • 18