Dear community,
it seems that the CodeCompletion plugin does not realise typedefs, right?
If I declare a struct as:
struct MyStruct
{
int iMyInt;
long lMyLong;
};
MyStruct ms;
CodeCompletion works well. However - as far as I know this is a C++ specific extension. The correct declaration in C (not C++) should be:
...where it doesn't work.
To solve the problem from above in C one normally uses typedefs. However, for:
typedef struct
{
int iMyInt;
long lMyLong;
}MyStruct;
MyStruct ms;
CodeCompletion doesn't seem to work eighter. Is this by design? It would be very nice if this were working since such typedefs are quite common in standard C.
With regards,
Morten.
I have thought of this issue again and had a look into the code of the CodeCompletion plugin. I am thinking of trying to implement what I have proposed. But before I try I'd like to ask a question:
within the file parserthread.cpp it seems that typedefs are handled in a way that they are simply skipped:
else if (token.Matches(_T("typedef")) ||
token.Matches(_T(":")))
{
SkipToOneOfChars(_T(";}"), true);
m_Str.Clear();
}
Am I right on this assumption? I wonder whether there is a reason for that?! I would like to know that reason before I might run into troubles I haven't thought of. Who is actually the author of this plugin?
With kind regards,
Morten.
within the file parserthread.cpp it seems that typedefs are handled in a way that they are simply skipped
That's true. Typedefs are not supported...
I wonder whether there is a reason for that?!
OK. Let's go by examples. Say you have this piece of code:
struct { ... } myStruct;
typedef struct myStruct myStruct;
With a little effort, we can make the plugin recognize it.
Now say you have this piece of code:
typedef ATemplatedClass<ClassType1, int, float>(AContainerClass::*WithAMemberFunction)(int,int);
// or
typedef BOOL (WINAPI *PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK)(PCCERT_CONTEXT,void*);
Well, without having access to the compiler's internals, how would the plugin find and identify correctly "WithAMemberFunction" or "PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK"?
I 'm open to suggestions.
Who is actually the author of this plugin?
Me.
I wonder if (and how) VC6 handles such complex typedefs? I currently haven't a valid code-snippet to test this... I'll try to find one.
Here's a simple one:
#include <iostream>
typedef void(*func)();
void AFunction()
{
std::cout << "In AFunction()" << std::endl;
return;
}
int main(int argc, char** argv)
{
func f = AFunction;
f();
return 0;
}
(Edit: fixed an error)
Here's a simple one:
Thanks! :D
Alright, I've had a look into VC6. I've used the following code:
#include "stdafx.h"
#include <iostream>
typedef struct
{
int iMyInt;
long lMyLong;
}MyStruct;
typedef void(*func)();
void AFunction()
{
std::cout << "In AFunction()" << std::endl;
return;
}
int main(int argc, char** argv)
{
func f = AFunction;
f();
return 0;
}
The result:
MyStruct and it's members is shown as a class in the class browser. Also codecompletion works for an instance ("ms"). The function typedef is ignored and not shown in the class browser. Is this handled as I proposed...?! MS seems to be is as lazy as I am. :lol:
So what to do from here? Is it worth giving a try? What do you (mandrav) think?
With regards,
Morten.
Edit: Did a mistake with quotes...
...I know, I said I shut up... but... :D
This is correct. MyStruct is not a type itself but a typedef for the anonymous struct behind it. After being typedef'd it is a type, of course ;)
Does that mean that
typedef struct {...} MyStruct;
is actually lazy syntax because it should better be:
typedef struct MyStruct {...} MyTypedef;
...and is just accepted by the generosity of the compiler?! I mean: itself without a name generates a compiler error (of course).
Seems I am learning something I had never thought of...
Morten.