Discussion:
Translating Free Pascal to GNU C
(too old to reply)
The Doctor
2005-05-30 19:49:35 UTC
Permalink
One word: HELP!

I got a programme written in Pascal which I am in the process of
translating into c. ptoc did a good job, still there are some
fixes that need to be done.

1)

/*try
getmem(molbuf,sizeof(molbuftype));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/

and

/*try
getmem(atom,n_atoms*sizeof(atom_rec));
getmem(bond,n_bonds*sizeof(bond_rec));
getmem(ring,sizeof(ringlist));
getmem(ringprop,sizeof(ringprop_type));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/

How isthis translated into C?

2) exit , what is the C equivalent?

3) beep, how do you say that in C?

4) /* str(n_atoms:1,tmpstr); lblank(3,tmpstr); */

How is this translated in C?

I am more likely available at ***@nk.ca .
--
Member - Liberal International
This is ***@nl2k.ab.ca Ici ***@nl2k.ab.ca
God Queen and country! Beware Anti-Christ rising!
insert you thought here.
Jack Klein
2005-05-30 23:02:15 UTC
Permalink
Post by The Doctor
One word: HELP!
I got a programme written in Pascal which I am in the process of
translating into c. ptoc did a good job, still there are some
fixes that need to be done.
1)
/*try
getmem(molbuf,sizeof(molbuftype));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/
and
/*try
getmem(atom,n_atoms*sizeof(atom_rec));
getmem(bond,n_bonds*sizeof(bond_rec));
getmem(ring,sizeof(ringlist));
getmem(ringprop,sizeof(ringprop_type));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/
How isthis translated into C?
2) exit , what is the C equivalent?
3) beep, how do you say that in C?
4) /* str(n_atoms:1,tmpstr); lblank(3,tmpstr); */
How is this translated in C?
So what makes you think that anyone who reads comp.lang.c or
comp.lang.c++ knows, or cares, anything at all about Pascal? What
makes you think that anyone reading comp.lang.pascal knows, or cares,
anything about C?

Perhaps you should hire a competent programmer.

What you posted doesn't look all that much like Pascal, at least not
as I remember it. Have they added a 'sizeof' keyword to Pascal
lately? Or 'try' and 'except'? It's been some time since I did
anything with Pascal, but I am pretty sure none of these are part of
the language.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
Chris McDonald
2005-05-30 23:11:27 UTC
Permalink
Post by Jack Klein
So what makes you think that anyone who reads comp.lang.c or
comp.lang.c++ knows, or cares, anything at all about Pascal?
...
...
What you posted doesn't look all that much like Pascal, at least not
as I remember it.
So, by your own admission, the OP was correct in their thinking that
someone who reads comp.lang.c knows something about Pascal.
--
Chris,
The Doctor
2005-05-31 00:30:42 UTC
Permalink
Post by Chris McDonald
Post by Jack Klein
So what makes you think that anyone who reads comp.lang.c or
comp.lang.c++ knows, or cares, anything at all about Pascal?
...
...
What you posted doesn't look all that much like Pascal, at least not
as I remember it.
So, by your own admission, the OP was correct in their thinking that
someone who reads comp.lang.c knows something about Pascal.
Enough comedy, just answer the question.
--
Member - Liberal International
This is ***@nl2k.ab.ca Ici ***@nl2k.ab.ca
God Queen and country! Beware Anti-Christ rising!
insert you thought here.
Rolf Magnus
2005-05-31 00:46:17 UTC
Permalink
Post by Chris McDonald
Post by Jack Klein
So what makes you think that anyone who reads comp.lang.c or
comp.lang.c++ knows, or cares, anything at all about Pascal?
...
...
What you posted doesn't look all that much like Pascal, at least not
as I remember it.
So, by your own admission, the OP was correct in their thinking that
someone who reads comp.lang.c knows something about Pascal.
However, in that case, the OP didn't seem to be correct in thinking that the
same "someone" also cares about Pascal.

*SCNR*
The Doctor
2005-05-31 00:35:06 UTC
Permalink
Post by Rolf Magnus
Post by Chris McDonald
Post by Jack Klein
So what makes you think that anyone who reads comp.lang.c or
comp.lang.c++ knows, or cares, anything at all about Pascal?
...
...
What you posted doesn't look all that much like Pascal, at least not
as I remember it.
So, by your own admission, the OP was correct in their thinking that
someone who reads comp.lang.c knows something about Pascal.
However, in that case, the OP didn't seem to be correct in thinking that the
same "someone" also cares about Pascal.
*SCNR*
Chemistry Profs writing in Pascal??
--
Member - Liberal International
This is ***@nl2k.ab.ca Ici ***@nl2k.ab.ca
God Queen and country! Beware Anti-Christ rising!
insert you thought here.
The Doctor
2005-05-31 00:30:08 UTC
Permalink
Post by Jack Klein
Post by The Doctor
One word: HELP!
I got a programme written in Pascal which I am in the process of
translating into c. ptoc did a good job, still there are some
fixes that need to be done.
1)
/*try
getmem(molbuf,sizeof(molbuftype));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/
and
/*try
getmem(atom,n_atoms*sizeof(atom_rec));
getmem(bond,n_bonds*sizeof(bond_rec));
getmem(ring,sizeof(ringlist));
getmem(ringprop,sizeof(ringprop_type));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/
How isthis translated into C?
2) exit , what is the C equivalent?
3) beep, how do you say that in C?
4) /* str(n_atoms:1,tmpstr); lblank(3,tmpstr); */
How is this translated in C?
So what makes you think that anyone who reads comp.lang.c or
comp.lang.c++ knows, or cares, anything at all about Pascal? What
makes you think that anyone reading comp.lang.pascal knows, or cares,
anything about C?
Perhaps you should hire a competent programmer.
What you posted doesn't look all that much like Pascal, at least not
as I remember it. Have they added a 'sizeof' keyword to Pascal
lately? Or 'try' and 'except'? It's been some time since I did
anything with Pascal, but I am pretty sure none of these are part of
the language.
Try Free Pascal.
Post by Jack Klein
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
--
Member - Liberal International
This is ***@nl2k.ab.ca Ici ***@nl2k.ab.ca
God Queen and country! Beware Anti-Christ rising!
insert you thought here.
Alf P. Steinbach
2005-05-30 23:24:30 UTC
Permalink
[Note: The OP crossposted to comp.lang.c, comp.lang.c++ and com.lang.pascal]
Post by The Doctor
I got a programme written in Pascal which I am in the process of
translating into c. ptoc did a good job, still there are some
fixes that need to be done.
1)
/*try
getmem(molbuf,sizeof(molbuftype));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/
Whatever language the above is, in C++ it would be like

try
{
getmem( molbuf, sizeof( molbuftype ) );
}
catch( Eoutofmemory const& )
{
std::cout << "Not enough memory" << std::endl;
std::exit( 4 );
}

Now it's natural to think that 'getmem' has something to do with
dynamic memory allocation, but you give no information about that.

The output should really be to the standard error stream, not to
standard output, but I've chosen to follow the original code
faithfully, warts and all -- it's Bad Code in several respects.
Post by The Doctor
...
How isthis translated into C?
2) exit , what is the C equivalent?
'exit'.

But in the code you've presented you've used 'halt'.

Which leads me to think you knew the answer to that one, and
accidentally let Freud slip your tongue.
Post by The Doctor
3) beep, how do you say that in C?
'beep'. Note that this is not a built-in or even standard library
name. You'll need to define its meaning.
Post by The Doctor
4) /* str(n_atoms:1,tmpstr); lblank(3,tmpstr); */
How is this translated in C?
Assuming it is a comment in whatever "Pascal" you're using (it's not
a standard Pascal comment), it's exactly the same in C and C++.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
The Doctor
2005-05-31 00:34:29 UTC
Permalink
Post by Alf P. Steinbach
[Note: The OP crossposted to comp.lang.c, comp.lang.c++ and com.lang.pascal]
Post by The Doctor
I got a programme written in Pascal which I am in the process of
translating into c. ptoc did a good job, still there are some
fixes that need to be done.
1)
/*try
getmem(molbuf,sizeof(molbuftype));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/
Whatever language the above is, in C++ it would be like
try
{
getmem( molbuf, sizeof( molbuftype ) );
}
catch( Eoutofmemory const& )
{
std::cout << "Not enough memory" << std::endl;
std::exit( 4 );
}
What about C?

I do not recall a try call in c.

E.EoutofMemory is Pascalish IIRC.
Post by Alf P. Steinbach
Now it's natural to think that 'getmem' has something to do with
dynamic memory allocation, but you give no information about that.
The output should really be to the standard error stream, not to
standard output, but I've chosen to follow the original code
faithfully, warts and all -- it's Bad Code in several respects.
Post by The Doctor
...
How isthis translated into C?
2) exit , what is the C equivalent?
'exit'.
But in the code you've presented you've used 'halt'.
Which leads me to think you knew the answer to that one, and
accidentally let Freud slip your tongue.
There was exit and halt, so halt I will replace with exit.
Post by Alf P. Steinbach
Post by The Doctor
3) beep, how do you say that in C?
'beep'. Note that this is not a built-in or even standard library
name. You'll need to define its meaning.
I was looking at curses, still.
Post by Alf P. Steinbach
Post by The Doctor
4) /* str(n_atoms:1,tmpstr); lblank(3,tmpstr); */
How is this translated in C?
Assuming it is a comment in whatever "Pascal" you're using (it's not
a standard Pascal comment), it's exactly the same in C and C++.
str?? I guess it was a string.
Post by Alf P. Steinbach
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
--
Member - Liberal International
This is ***@nl2k.ab.ca Ici ***@nl2k.ab.ca
God Queen and country! Beware Anti-Christ rising!
insert you thought here.
Rolf Magnus
2005-05-31 01:05:56 UTC
Permalink
Post by The Doctor
Post by Alf P. Steinbach
Post by The Doctor
1)
/*try
getmem(molbuf,sizeof(molbuftype));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/
Whatever language the above is, in C++ it would be like
try
{
getmem( molbuf, sizeof( molbuftype ) );
}
catch( Eoutofmemory const& )
{
std::cout << "Not enough memory" << std::endl;
std::exit( 4 );
}
What about C?
C doesn't support exceptions.
CBFalconer
2005-05-31 01:12:47 UTC
Permalink
Post by The Doctor
One word: HELP!
I got a programme written in Pascal which I am in the process of
translating into c. ptoc did a good job, still there are some
fixes that need to be done.
1)
/*try
getmem(molbuf,sizeof(molbuftype));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/
To start with, this isn't Pascal. However, just looking at the
sense of what it seems to be trying to do, I suggest:

if (!(molbuf = malloc(sizeof *molbuf))) {
fputs("Not enough memory\n", stderr);
exit(EXIT_FAILURE);
}
/* success, continue */
Post by The Doctor
and
/*try
getmem(atom,n_atoms*sizeof(atom_rec));
getmem(bond,n_bonds*sizeof(bond_rec));
getmem(ring,sizeof(ringlist));
getmem(ringprop,sizeof(ringprop_type));
except
on e:Eoutofmemory do
begin
writeln('Not enough memory');
halt(4);
end;
end;*/
How isthis translated into C?
Suggestion:

/* this statement allows for freeing if any one
of the allocation group fails */
atom = bond = ring = ringprop = NULL;
if (!(atom = malloc(n_atoms * sizeof *atom)) ||
!(bond = malloc(n_bonds * sizeof *bond)) ||
!(ring = malloc(sizeof *ring)) ||
!(ringprop = malloc(sizeof *ringprop)) ) {
fputs("Not enough memory\n");
if (atom) free(atom);
if (bond) free(bond);
if (ring) free(ring);
exit(EXIT_FAILURE);
}
/* allocations successful, onward */

(all of which assumes that what is wanted is space for one item of
the type to which the pointers point, or an array of such for atom
and bond).
Post by The Doctor
2) exit , what is the C equivalent?
In C, exit exits the complete program. If you are thinking of the
abortion of an extension in some quasi Pascal systems where exit
exits the procedure/function, just use 'return'. For a function
use "return value". In future write the Pascal correctly, such as:

PROCEDURE foo;
LABEL 10;
BEGIN
....
IF bar THEN GOTO 10;
....
10: END;
Post by The Doctor
3) beep, how do you say that in C?
System dependent.
Post by The Doctor
4) /* str(n_atoms:1,tmpstr); lblank(3,tmpstr); */
How is this translated in C?
No idea. What is it supposed to do? Again, it isn't Pascal.

Followups set, because this has nothing to do with C++, and
comp.lang.pascal has been split into various subgroups for many
years now, and should not be used. I chose comp.lang.pascal.misc
because the original has no resemblance to real Pascal.
--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
Continue reading on narkive:
Loading...