Author |
Topic |
|
PatLuja
Tomato Guru
Belgium
416 Posts |
Posted - Jan 13 2005 : 05:27:51 AM
|
Hello all,
It seems that functions that are declared in header files as "static inline", do confuse the definition bar. One example:
In my header file I have the following function: static inline bool SetSomething(const char* string1, const char* string2, const char* string3); This is implemented in a cpp file. When I use this function in yet another cpp file and click on the name of this function, I'll see the following in my definition bar: static inline class <MyClass1> static inline class <MyClass2> static inline void static inline float static inline float static inline void static inline int static inline bool static inline bool static inline class <MyClass3> SetS where <MyClass?> stands for some class use somewhere in the code (in unrelated header and cpp files).
Could you please look into this. It's not very critical, but it would be handy if it works. Thank you.
With kind regards, Patrick Luja |
|
schoenherr
Tomato Guru
Germany
160 Posts |
Posted - Jan 14 2005 : 12:57:26 AM
|
Hello Patrick, do you really think implementing an inline function in a cpp is a good idea? From memory i would say you could use this function only in cpp's of the same module/library, otherwise you should get linker errors. |
|
|
PatLuja
Tomato Guru
Belgium
416 Posts |
Posted - Jan 14 2005 : 02:34:15 AM
|
Hello schoenherr,
The static inline function is defined in the header file and implemented in the cpp file. It is a private function and this class has no friends, so there is no complaining from the linker. Another option is to implement this function inside the header file, or directly after the definition. The later I do when it is only one or two instructions, while I think (imho) the prior is against the meaning of the header file.
You are right that you can't do this with public of protected functions, nor if the class has friends (which don't use the same header and cpp-file).
Thank you for your reaction.
With kind regards, Patrick Luja
P.S. feline, WannabeDeveloper or support can you reproduce this? I'm using VA X build 1293. |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Jan 16 2005 : 6:05:18 PM
|
so far i cannot reproduce this problem.
using VAX 1287, .NET 2003 with C++ i have added your definition to a settings class with a friend configure class. i then added an empty body in the setting class's cpp file. surprisingly enough this compiles and runs.
when i then reference this function in the friendly configure class cpp file the code does not compile, since the definition of the inline function is unavailable, turning it into an unresolved external.
ignoring this i placed my caret inside the function name. the VAX definition bar is showing me only one entry for this function, which is correct.
from your description, surely you are having to #include one cpp file into another cpp file for this code to compile. or am i missing some detail?
i am guessing in your case the second cpp file also contains class member functions. however i would not expect this to compile any more readily than my example, since the function body is still invisible to the compiler, isn't it?
i am guessing you have done something interesting to get this to work, and this may be the cause of VAX's confusion. |
zen is the art of being at one with the two'ness |
|
|
PatLuja
Tomato Guru
Belgium
416 Posts |
Posted - Jan 17 2005 : 07:47:50 AM
|
Dear feline,
It's not as hard as you think. It is just a class, without any friends. The static inline bool function (mentioned in my origional posting) is located in the private section. There is just a normal .cpp file that implements this. (No hard-to-understand coding techniques are used...) In another .cpp file, that includes only the header file of the class with this function. It is in this last .cpp file that the definition bar gives so much other static inline things...
Maybe I must say that there are many .h and .cpp files containing a static inline function, that is implemented in a .cpp file. I do not recall if more of these classes where included in the .cpp file that "confuses" the definition bar.
I hope, you are able to reproduce it. If you have more questions, please ask.
With kind regards, Patrick Luja |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Jan 24 2005 : 1:06:57 PM
|
this all seems to make sense, but i don't follow how you manage to use this static inline function in the second cpp file
are you inside a class member function in the second cpp file? personally i always try to keep to one cpp file and one .h file per class, so i would not expect member functions in two files.
if it is not a member function, how can it see a private class member function?
also i am curious as to how this manages to compile, since my understanding was that the compiler required access to the definition of an inline function in order to inline it. i thought you could not look into a second (non included) cpp file until you got to the linker stage, after inline functions have to be inlined.
does this make sense? this is just my understanding, so i could be wrong
i am trying to see what you have done, so i can try to reproduce the effect you are seeing. so far VAX is not having problems, but i very rarely use the inline keyword in my code, preferring to just define small inline functions in the header files directly. |
zen is the art of being at one with the two'ness |
|
|
PatLuja
Tomato Guru
Belgium
416 Posts |
Posted - Feb 02 2005 : 03:45:49 AM
|
Hello all,
feline, in search of the point where I saw this, I discovered a clue which I send to support.
I seems it starts at a point looking like:#ifdef SOMETHING
#define SOMECLASS MyClass1
#else
#define SOMECLASS MyClass2
#endif
// ...
static inline class SOMECLASS GetSomething(const char* name) {
// some code
} The "static inline" functions starting with this one are displayed in a wrong way. The problem is probably allocated in the parsing of the header file.
As said; I've mailed my information to support, so I hope we can hear "We've fixed it" from them soon.
With kind regards, Patrick Luja
P.S. I couldn't find the spot I was talking about earlier, so at this moment I'm not able to answer your question. |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Feb 07 2005 : 3:30:35 PM
|
i have just had another go at this, and i am still not able to reproduce the problem. hopefully the info you sent support will help |
zen is the art of being at one with the two'ness |
|
|
PatLuja
Tomato Guru
Belgium
416 Posts |
Posted - Feb 09 2005 : 03:26:37 AM
|
I hope so too.
With kind regards, Patrick Luja |
|
|
|
Topic |
|