Inlining in Xcode

Atomical
Unregistered
 
Post: #1
My function definitions match perfectly yet I'm getting undefined symbols.

ld: warning prebinding disabled because of undefined symbols
ld: Undefined symbols:
instr(char*, char*)


Here is my stringutils.h file:

inline int instr ( char *src , char *find );

Here is my stringutils.cpp file:

inline int instr ( char *src , char *find ) {
char *s = strstr ( src, find );
if ( s != NULL )
return 1;
else
return 0;
}


Do I have to configure the compiler for inline?
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #2
Inline definitions have to be in the header file, that's all.
Quote this message in a reply
Atomical
Unregistered
 
Post: #3
Will inline affect my development builds when I debug them?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
functions aren't inlined in debug builds.
Quote this message in a reply
Atomical
Unregistered
 
Post: #5
One more question.. header_informat is a struct. I'm trying to store values in a struct that is in an array. I've paseed it as a double pointer. How do I access it?


int auth2 ( char*header, struct header_information** parsed, int &hcount ) {

parsed[hcount].id = atoi ( typebuf );

}
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #6
You don't need a double pointer for this (unless you want to realloc the array). Also, if you add a "typedef struct header_information header_information;" below the struct header_information declaration, you can eliminate the need to add struct in front of it everywhere:
Code:
int auth2(char *header, header_information *parsed, int &hcount) {
    parsed[hcount].id = atoi(typebuf);
}
Quote this message in a reply
Atomical
Unregistered
 
Post: #7
I wanted to be able to reallocate it inside the function. I don't use the typedef and I don't have to put struct in front of it everywhere.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #8
typedef'ing structs isn't neccesary in C++, I guess you are using the C++ compiler?

OK, if you need to realloc then:
Code:
int auth2(char *header, header_information **parsed, int &hcount) {
    ...
    (*parsed)[hcount].id = atoi(typebuf);
    ...
}
Quote this message in a reply
Atomical
Unregistered
 
Post: #9
I added the compiler flag:

-finline-functions

And I put inline in my header file but I get an undefined symbol on deployment builds.

ld: warning prebinding disabled because of undefined symbols
ld: Undefined symbols:
instr(char*, char*)


Do c++ header files need to be .hh instead of .h?
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #10
Are you sure you put the entire function into the header?
Quote:Do c++ header files need to be .hh instead of .h?
Nope.
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #11
Atomical Wrote:I added the compiler flag:

-finline-functions

FYI, that is enabled on -O3 and is redundant if you've already got -O3. It isn't enabled on -O2 or -Os.

There is also -finline-limit=n , which tweaks how large of functions get inlined. The default is 600 pseudo instructions. Be aware that bigger is not always better.

And don't listen to me, the manual is more informative: http://www.gnu.org/software/gcc/onlinedocs/

Cheers,
-Jon
Quote this message in a reply
Post Reply