3

In the sqlite3_open function (Generic C function), I need to send the address of the sqlite3 generic C pointer as an argument.
Example:

//Valid code
NSString * databaseFile; //Path of database file. (Objective-C Object)
sqlite3 * db; //Pointer to hold the sqlite database. (C Pointer)

sqlite3_open([databaseFile UTF8String], &db); //db is sent using the & operator.

The problem is that I need to get *db variable from inside an object. I KNOW this code is wrong, but it is a way to explain what I need:

//I need to get the address of the pointer 'database' from inside the Objective-C Object 'object'.
//I hope one of those wrong lines explain what I want:

sqlite3_open([databaseFile UTF8String], &[object database]);
sqlite3_open([databaseFile UTF8String], [object &database]);
sqlite3_open([databaseFile UTF8String], &(object->database);

I hope someone undertands me... Hahaha Thank you for your time! =)

Bruno Philipe
  • 1,091
  • 11
  • 20
  • You probably want to set up a temporary var `database`, then pass `&database` to `sqlite3_open()`, and then call `[object setDatabase:database]` (or `object.database = database`) – nielsbot Oct 25 '12 at 01:45
  • I assume when you say "from inside an object" you mean by referencing a property. Keep in mind that a property reference turns into an invocation of a getter or setter method. You can't "take the address" of a property. – Hot Licks Oct 25 '12 at 01:48
  • @nielsbot YES! Thank You! This was so simple... I was wandering around this problem for so long that I forgot I could simply do the opposite. Please set this as an answer so I can upvote it. :) – Bruno Philipe Oct 25 '12 at 01:50

1 Answers1

1

Assuming MyClass looks like this:

@interface MyClass : NSObject
...
@property ( nonatomic ) sqlite3 * database ;
...
@end

Your code would be:

MyClass * object = ... ;

sqlite3 * database ;
sqlite3_open( ..., & database ) ;

object.database = database ;
nielsbot
  • 15,922
  • 4
  • 48
  • 73