Ask your own question, for FREE!
Computer Science 10 Online
OpenStudy (anonymous):

so I've got 2 C files (http://ideone.com/Queyp ) am I using extern properly? Is this the proper way to declare something in a header, and then define it in the source file?

OpenStudy (anonymous):

Yes, that looks good. Of course the extern declaratonis will only be needed if another file includes the header. By the way, on the subject of the inline keyword: -It'll only make a difference in an optimized build. Debug builds won't inline anything (with the exception noted below). -These days, it'll rarely make a difference even in an optimized build. The inline keyword is a hint to the compiler that you want this function inlined, but it doesn't mean the compiler will actually do it. Most of today's optimizers will ignore the inline keyword altogether and just do whatever their heuristics tell them. I've run tests on larger code bases with no keyword, with inline, and with the corresponding force inline directives for MSVC and GCC, and the resulting assembly code was identical in almost all cases. The force inline directives (__forceinline in MSVC, attribute(always_inline) in GCC), however, will inline a function even in debug mode. It can be a good way to keep debug mode code reasonable performance wise.

OpenStudy (anonymous):

so I type in #pragma always_inline ?

OpenStudy (anonymous):

or do I do it like this \[inline void* dmalloc(unsigned long size) __attribute__((always_inline)); inline void* drealloc(void* object, unsigned long size) __attribute__((always_inline)); inline void dfree(void* object) __attribute__((always_inline)); inline void dprint(void) __attribute__((always_inline));\]

OpenStudy (anonymous):

No - for GCC, simply declare your function like so: inline void myfunction() __attribute__(always_inline); (see also http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Function-Attributes.html) Note that you need both the attribute and the inline keyword. This will give you the same inlining in debug builds as it will in optimized builds - if I'm not mistaken, however, it's still not a guarantee that the function will inline.

OpenStudy (anonymous):

Yes, with double parentheses.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!