Can you help me wit this translation attempt pls?

A

almurph

Hi everyone,


Hope you can help me with this one and its not too left field. I have
some pre-99 C code that requires translation into C#. The C code
involves pointers and the translation does not use any. The
translatino also tries to simplfy the C code into a kind of easier to
read code.


I would apprecte your comments/suggestions/suggestions/blessings to
make sure I'm on the right track. Oh BTW, it should be noted that
Weight below is an array of type double.

Thanking you,
Al.


*** BEGIN C LANGUAGE CODE ***


int A, B;
double *Wb, *Wa;
double Sum=0.0;


for ( Wb = Weight + B, Wa = Weight + A ; Wb <= Wa ; )
{
Sum += *Wb++;
}


*** END C LANGUAGE CODE ***



*** BEGIN C# ATTEMPT ***

double Sum = 0.0;
double Wt_Value;

for (double Wt = Weight; Wt <= Weight[A]; Wt++)
{
Wt_Value = Wt;
Sum = Sum + Wt_Value;
Wt = Wt + 1;
}

return Sum;


*** END C# ATTEMPT ***
 
A

almurph

(e-mail address removed) said:




Hi everyone,
Hope you can help me with this one and its not too left field. I
have some pre-99 C code that requires translation into C#. The C
code involves pointers and the translation does not use any. The
translatino also tries to simplfy the C code into a kind of easier
to read code.
I would apprecte your comments/suggestions/suggestions/blessings
to make sure I'm on the right track. Oh BTW, it should be noted
that Weight below is an array of type double.
Thanking you,
Al.
*** BEGIN C LANGUAGE CODE ***
int A, B;
double *Wb, *Wa;
double Sum=0.0;
for ( Wb = Weight + B, Wa = Weight + A ; Wb <= Wa ; )
{
        Sum += *Wb++;
}

You might find the following version (which I believe to be
equivalent, or as equivalent as possible) to be easier to
translate.

int A = WhatIsThisSupposedToStartWith();
int B = AndWhatAboutThisOne();
double Sum = 0.0;
while(B <= A)
{
  Sum = Sum + Weight;
  B = B + 1;

}

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999- Hide quoted text -

- Show quoted text -


Wow Richard, thanks, very nice & neat man, cool.
Cheers & thanks again,
Al.
 
F

Fred

(e-mail address removed) said:




Hi everyone,
Hope you can help me with this one and its not too left field. I
have some pre-99 C code that requires translation into C#. The C
code involves pointers and the translation does not use any. The
translatino also tries to simplfy the C code into a kind of easier
to read code.
I would apprecte your comments/suggestions/suggestions/blessings
to make sure I'm on the right track. Oh BTW, it should be noted
that Weight below is an array of type double.
Thanking you,
Al.
*** BEGIN C LANGUAGE CODE ***
int A, B;
double *Wb, *Wa;
double Sum=0.0;
for ( Wb = Weight + B, Wa = Weight + A ; Wb <= Wa ; )
{
        Sum += *Wb++;
}

You might find the following version (which I believe to be
equivalent, or as equivalent as possible) to be easier to
translate.

int A = WhatIsThisSupposedToStartWith();
int B = AndWhatAboutThisOne();
double Sum = 0.0;
while(B <= A)
{
  Sum = Sum + Weight;
  B = B + 1;

}



sum = 0.0;
for ( i=B; i < A; i++ ) {
sum += Weight;
}
 
C

CBFalconer

Hope you can help me with this one and its not too left field. I
have some pre-99 C code that requires translation into C#. The C
code involves pointers and the translation does not use any. The
translatino also tries to simplfy the C code into a kind of
easier to read code.

c.l.c deals only with the C language, as described in the ISO C
standard. C# is another language, and has no connection to real
C. Go to another newsgroup, probably something with microsoft in
the name.
 
L

luserXtrog

Wrong. c.l.c deals with the C language is used in the real world. ISO C
is one variation.

To the OP, most people will help if able : do not allow Falconer to put
you off. He's a clueless old busy body.

While his tone may have been unfriendly, the advice is sound.
C# is a different language and there's likely a more useful
place for these questions.
 
L

luserXtrog

The following is the complete actual message I posted, without the
cuts imposed by the trolls.  Where do you find it to be
'unfriendly'?

The imperative mood: "Go to another newsgroup...". It is an order, a
command. The sentence could be constructed more politely as a
pertinent assertion: "You will receive better help in another
newsgroup...".

Although I do enjoy the suggestion that C# is unreal.
But, dude, I'm on *your* side here, don't lump me in!
I ought not to be held responsible for a previous snip in a thread.
 
J

James Kuyper

CBFalconer said:
c.l.c deals only with the C language, as described in the ISO C
standard. C# is another language, and has no connection to real
C. Go to another newsgroup, probably something with microsoft in
the name.

His question is about translation between C and C#. What he needs is
help from someone who knows a lot about both languages. In the abstract,
he's just as likely to find such a person in comp.lang.c as in a
newsgroup devoted to C#, and it's just as reasonable (or just as
unreasonable) to post to either newsgroup.

In practice, given the historical relationship between C and C#, he's
more likely to find such double-experts in the C# newsgroup than here.
He should be well aware of that fact by now, he's been informed of it
multiple times, and he keeps ignoring that advice and posting his
questions in a less appropriate place anyway.
 
J

JosephKK

Try microsoft.public.dotnet.languages.csharp

It seems to propagate beyond news.microsoft.com

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top