CHTH0NIC

I am porting an application from procedural C to Managed C++ so this might be the first of a few questions.

The following two combined typedefs are legal in C what would the equivalent be in MC++.

Code Snippet
typedef unsigned char uchar;
typedef uchar bool;

Secondly the following is legal in C, how would you change it for MC++

Code Snippet

bool (*validator)(struct _Variable *, void *new);


but now it complains about the "*new". Is there an equivalent in MC++

Thanks for your help.


Re: Visual C++ Language C port to Managed C++ Questions (nothing long-winded!)

Bruno van Dooren

char and bool are primitive types. you don't have to typedef them. so that snippet can disappear.

The reason that the compiler complains about '*new' is that 'new' is a keyword in C++. It it used to instantiate objects and allocate heap memory.

'_Variable' also doesn't need the struct keyword anymore.





Re: Visual C++ Language C port to Managed C++ Questions (nothing long-winded!)

Ramkrishna Pawar

The first snippet code is still legel in C++ and MC++, so let it be as it is, just make sure that you do not place both the statemants in same unit (which is wrong in C too).

In C++ 'new' is a keyword (operator), used to allocate memory (just like malloc), so you need to choose different name for your void pointer.






Re: Visual C++ Language C port to Managed C++ Questions (nothing long-winded!)

CHTH0NIC

Thanks for the replies. I figured that was the case regarding the second code snippet, it was just the syntax highlighting in the IDE that threw me off.

As regards the first code snippet, it compiles up as C code but doesn't as C++.
error C2628: 'uchar' followed by 'bool' is illegal (did you forget a ';' )

What do you mean by "the same unit". In the original code they are in the same file, one line after the other.

Thanks again.





Re: Visual C++ Language C port to Managed C++ Questions (nothing long-winded!)

Bruno van Dooren

bool is a primitive type in C++ already. You are not allowed to change its meaning through a typedef.



Re: Visual C++ Language C port to Managed C++ Questions (nothing long-winded!)

CHTH0NIC

Thanks. I take it the following method signature is wrong for the same reason. 'operator' is not a keyword in C but it is a keyword in C++:

Code Snippet

static Operator operator(const char *s, int *i) ;







Re: Visual C++ Language C port to Managed C++ Questions (nothing long-winded!)

Ramkrishna Pawar

thats right !