Re: Help with C->C# Port
- From: Mehdi <vioccc@xxxxxxxxxxxxxxxxxx>
- Date: Sun, 7 May 2006 17:17:57 +0100
On Sun, 7 May 2006 10:43:31 -0500, farc wrote:
I am in the process of converting an old C application to C#. The
application is loaded with pointers (as most are, I guess). How would I best
represent the following structures in C#?
You are probably aware of this but in case you're not: the difference
between C and C# is much greater than just a syntax difference. C is a
procedural language while C# is a OO language. C# programs are therefore
organized and designed in a completely different way than C programs are
and porting form C to C# usually involves much more than just changing the
syntax. Instead of simply doing a litteral port, It's usually better to
understand what the program does and then design a C# program that does the
same thing but using an OO approach.
typedef char ** mytypedef;
In C:
- char is a character. In C#, you would use the Char structure to store a
character. Note that in C, char can actually be used to store any 1 byte
value while in C#, Char represents a unicode (2 bytes) character and only
that.
- *char is a pointer to character. This is usually used to point to a null
terminated character string. For this, you would use a string in C#
- **char is a pointer to a pointer of char. This can for instance be used
to pass a string as a parameter to a function that might return a pointer
to another string via the same parameter. In C#, you would either pass a
string as a ref parameter or simply return a new string as the return value
of the function.
- typedef char ** mytypedef; defines mytypedef as being a **char. Any
variable declared as being a mytypedef would therefore be a **char
variable. In other words, mytypedef really is an alias for **char. In C#,
there is no typedef. Instead, there is the much safer and more powerfull
concept of classes.
typedef struct _mystructure {
struct _mystructure *left, *right;
} mystructure;
There are struct in C# too. However, my knowledge of the C syntax shows its
limits here and i can't really say what this struct declaration actually
does.
.
- Follow-Ups:
- Re: Help with C->C# Port
- From: Göran Andersson
- Re: Help with C->C# Port
- From: Karch
- Re: Help with C->C# Port
- References:
- Help with C->C# Port
- From: farc
- Help with C->C# Port
- Prev by Date: Freeing Memory Allocated By Unmanaged Dlll
- Next by Date: Re: Help with C->C# Port
- Previous by thread: Help with C->C# Port
- Next by thread: Re: Help with C->C# Port
- Index(es):
Relevant Pages
|