Skip to main content
gamedev.net
🔒 Locked

Inline code in C++

Started by Graham11 Nov 24, 2004 at 8:30 AM 3 replies 1k views
Original Post
Graham11
Graham11
Hi All, I've been working on a C++ library for some time, and have many inlined methods, often in their own *.inl files. One of our licensing models doesn't include sourcecode, but such inline methods ARE effectively sourcecode and would seem necessary for the distribution. Is there any way I can avoid re-engineering the project if I do not want a library-only release to include such inlined information? Best wishes, Graham
hh10k
hh10k
If you want them to be inlined then the library user will need the code. I think your two options are:

1) Change the license to allow for the inlined code.
2) Disable inline for the restricted license. I would probably do this by #defining a PUBLIC_INLINE (or something) that would be 'inline' in your open licenses, and nothing for the closed license.
Fruny
Fruny
No. You'll have to make them non-inline (inline is only a compiler hint anyway). Create an additional header with the function declarations and do compile your .inl file as if it were a normal C++ file (may require telling your compiler it really is a C++ file), using the preprocessor to eliminate the inline keywords (having an INLINE macro might help).

It can be considered 're-engineering', but as far as such things go, it shouldn't be a major problem.

Foo.h
int Foo();#ifdef USE_INLINE_FUNCTIONS#  include "Foo.inl"#endif

Foo.inl
#ifdef USE_INLINE_FUNCTIONS#  define INLINE inline#else#  define INLINE#endifINLINE int Foo(){  return 0;}#undef INLINE


Your code should include "Foo.h" and never explicitely include "Foo.inl". If USE_INLINE_FUNCTIONS is not defined (or some other conditional compilation trick), "Foo.inl" won't be included and will have to be compiled separately. Add a suitable target to your project (or makefile) so that they do get compiled in. It should be possible to have the project also take care of #defineing USE_INLINE_FUNCTIONS when the suitable target is selected.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Shannon Barber
Shannon Barber
Quote:
Original post by Graham11
Hi All,

I've been working on a C++ library for some time, and have many inlined methods, often in their own *.inl files. One of our licensing models doesn't include sourcecode, but such inline methods ARE effectively sourcecode and would seem necessary for the distribution.

Is there any way I can avoid re-engineering the project if I do not want a library-only release to include such inlined information?

Best wishes,
Graham


I assume it's an SDK and you deliver dll's; you still need the header files, isn't that technically source code? Can the .inl stuff be considered part of the headers then?
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.