0

Not sure if this is even possible since I don't have much experience with either language but if I have a file driver.c and with in it have something like this

char *getData(int user){
    unsigned char *buffer = malloc(2800);

    // ... do all the stuff

    return buffer;
 }

int main(int argc, const char * argv[]){
   int user = 1;

   unsigned char *buffer = getData(user);

   return 0;
}

Would I be able to access the buffer variable that is created with in the main() function from another file/class that is written in Objective-C?

Stavros_S
  • 2,145
  • 7
  • 31
  • 75
  • @Merlevede so if with in the driver.h file I set "extern usigned char *buffer;" Then I would be able to access it from any other file in the application since this would be making it global? – Stavros_S Mar 06 '14 at 22:05
  • Can you create a shared memory space, such as a file? – Fiddling Bits Mar 06 '14 at 22:07
  • @FiddlingBits Not quite sure what you mean actually. – Stavros_S Mar 06 '14 at 22:11
  • 1
    So, since this was immediately closed as a duplicate, apparently, the only way to share data between a class and a function is to use global variables? Funny, because I'd have thought passing it as a parameter in a method might have worked too (assuming he renames `driver.c` to `driver.m`)... – NSGod Mar 06 '14 at 22:35
  • @NSGod I'm fine changing the file type to .m What In the end I'm trying to achieve here is just making this code that I wrote in C http://pastebin.com/ufbvziUR return a buffer that can be consumed by another part of the app. – Stavros_S Mar 06 '14 at 23:02

0 Answers0