Re: Help with C->C# Port



Thanks for the reply. Yes, I'm quickly realizing that a rewrite is probably
the best approach. After looking more closely, I know that generics along
with .net system types will probably solve most of my issues.

"Mehdi" <vioccc@xxxxxxxxxxxxxxxxxx> wrote in message
news:1dbpdhflaorl2.1r43dbasaf6pa$.dlg@xxxxxxxxxxxxx
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.


.



Relevant Pages

  • Re: split a string
    ... But this reads a string into a single char ... Check fgetsfrom the Standard C Library as a way to get string input ... pointer to a pointer to a char. ... To handle arrays remotely. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: The type of argv in K&R2
    ... has type pointer to character strings. ... members of that array each point to the first character of a string that ... The next member, the member, ...
    (comp.lang.c)
  • Re: copy a string into a 2d array of chars
    ... This split function should allocate a 2D array of chars ... >focus the program the string is not actually split. ... later) is an array of char containing the original contents of the ... The i-th pointer will contain the starting address of the ...
    (comp.lang.c)
  • Re: problem with function
    ... > If you intended copying the string, you need to use the strcpy function. ... I suggest researching hungarian notation for variable names. ... Isn't 'psz' a pointer a an array of characters containing a string? ... pointer to char. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: How to mid string on a binary string?
    ... > return a pointer from that postion to the end of the binary stirng. ... I don't know how I can do a char ... just what you mean by "binary string". ... including the first null character". ...
    (comp.lang.c)

Quantcast