c/pascal compiler differences

S

Skybuck Flying

Hi,

I think I understand now a bit better what the difference is between a c
compiler and a pascal compiler.

For example:

When compiling source code with a pascal compiler. The pascal compiler will
simply stop when it is missing an implementation for a procedure or
whatever.

The c compiler however will simply continue compiling even if the
implementation for the headers/prototypes are missing.

The c linker will then report a big list of link errors.

Both methods have benefits and drawbacks. The pascal compiler is more
simple... it allows one to simply proceed from error to error until it
completely compiles and links.

The drawback of the c compiler might be the suspended error reporting...
it's a bit wacky... since one can not jump to the location where the stuff
is missing ?

or maybe one can... it's a bit wacky...

Though I can clearly see a benefit for a c compiler since it simply compiles
even though the implementation is completely missing.

One could later even make different implementations and simple re-use the
already compiled stuff and link against it.

So one can end up linking different kind of stuff against the same compiled
C file.

I think this is correct though I never really tried it.

Are there any good examples where this C/link freedom is used ?

Does a pascal compiler have the same link freedom ? ( meaning prototype
available but implementation missing )

I think not... ?

Bye,
Skybuck.
 
M

Maarten Wiltink

I think I understand now a bit better what the difference is between a
c compiler and a pascal compiler.

For example:

When compiling source code with a pascal compiler. The pascal compiler
will simply stop when it is missing an implementation for a procedure
or whatever.

The c compiler however will simply continue compiling even if the
implementation for the headers/prototypes are missing.

Pascal was specifically designed to allow one-pass compilation. So
whenever something is missing, that's an instant error. C, also by
design, is much looser. You can put a "void writeln();" pretty much
anywhere in your code, and there is no error until you try to link
together an executable that doesn't have a writeln procedure somewhere.
There's a keyword "extern", but it may be omitted.

Groetjes,
Maarten Wiltink
 
C

CBFalconer

Skybuck said:
I think I understand now a bit better what the difference is
between a c compiler and a pascal compiler.

.... snip gross misconceptions ...

The fundamental difference is the source language. Anything else
is a frill. c.l.c deals solely with the language, and not the
compilers. The languages are defined by the ISO standards.

BTW, Pascal is always capitalized.
 
N

Nicolai Hansen

When compiling source code with a pascal compiler. The pascal compiler will
simply stop when it is missing an implementation for a procedure or
whatever.

The c compiler however will simply continue compiling even if the
implementation for the headers/prototypes are missing.

The c linker will then report a big list of link errors.

C got two stages of compiling, compilation and linking. Pascal doesn't
use linking (here it is a part of the normal compilation). In C it is
not a compilation error if an implementation of a method/variable is
missing; it is a linker error. In Pascal it is a compiler error as it
links while compiling.

Of course you can make a program with a button which, on clicking,
will run "MyMethod()" which is defined in "blah.h" but missing the
implementation. You can then compile ten different object files with
ten different implementations of MyMethod(), then link them into ten
different programs with ten different things happening when you click
the button.

But you can do that same thing in Pascal, make your onclick run
MyProcedure(), make ten different MyProcedure() implementations, then
add one of them to your uses. Generates the same as the C linker. It
will compile the whole thing everytime (unlike C where only the linker
is run), but in Pascal you can actually have all ten implementations
of MyProcedure() in the same project ;)
 
B

Bruce Roberts

Does a pascal compiler have the same link freedom ? ( meaning prototype
available but implementation missing )

I think not... ?

As usual you think wrong. See the External Declarations entry in the Delphi
help. Pay particular attention to the $LINK compiler directive.
 
S

Skybuck Flying

Bruce Roberts said:
As usual you think wrong. See the External Declarations entry in the Delphi
help. Pay particular attention to the $LINK compiler directive.

When is it linked into it ?

Occurding to some posts... compiling and linking is the same thing in
pascal.

So it's actually linked in at compile time... that would be my guess.

That's still fundamentally different than C ;)

Unless I am mistaking :D
 
F

Flash Gordon

When is it linked into it ?

Occurding to some posts... compiling and linking is the same thing in
pascal.

So it's actually linked in at compile time... that would be my guess.

That's still fundamentally different than C ;)

Unless I am mistaking :D

It all depends on WHICH Pascal variant you are talking about. I've used
versions of Pascal where the Linking was done at run time.

The original Pascal definition did not support separately compiled
modules so there was not much linking to be done. Later extensions added
separate compilation of modules at which point linkers became involved
and worked basically the same as they do for C. However, the language
definition still included (and probably still does) a requirement to
declare before first use, something the original C did not (I can't
remember if C99 has added that but some compilers provide it as an
extension). To allow for things like mutually recursive functions Pascal
included a forward declaration which gives the compiler the signature of
the function and tells it to resolve it further down the file.

Also, whilst Pascal and C are very different languages in many respects
there are implementations which provide mechanisms for linking C code
and Pascal code, so the linkage requirements of the languages can't be
mutually incompatible. However, the method for linking the two languages
is off topic for this group. :)
 
B

Bruce Roberts

Occurding to some posts... compiling and linking is the same thing in
pascal.

So it's actually linked in at compile time... that would be my guess.

That's still fundamentally different than C ;)

Delphi first compiles units then it links the project. If all units are
up-to-date, essentially the only thing that happens is the linking.
 
X

Xenos

Bruce Roberts said:
As usual you think wrong. See the External Declarations entry in the Delphi
help. Pay particular attention to the $LINK compiler directive.
That Delphi, not standard Pascal.
 
S

Skybuck Flying

Bruce Roberts said:
Delphi first compiles units then it links the project. If all units are
up-to-date, essentially the only thing that happens is the linking.

Ok, let's take it to the test:

procedure unimplemented;

begin

unimplemeted;

end.

void unimplemented();

int main()
{

unimplemented();

}

Without actually having given ;) it a try I think the delphi/pascal example
won't even compile :) and the C version will just like that :D

Is there a way to make the pascal example compile and then later link
different files to it ? ( I think not ? )

The difference is: I could distribute my compiled C program to anybody...
and tell them to simply implement a few function and link it and suprise
suprise it would actually work :D

Lol, I think pascal/delphi will be another story !

Bye,
Skybuck.
 
B

Bruce Roberts

Ok, let's take it to the test:
Without actually having given ;) it a try I think the delphi/pascal example
won't even compile :) and the C version will just like that :D

It helps to read the documentation. I gave you a specific reference, if you
had read it you would see that, with the correct syntax, your Delphi would
have compiled just fine.
 
F

Flash Gordon

That Delphi, not standard Pascal.

Similar things apply to every Pascal implementation I have used, and
that is quite a few. I believe that ISO standard Pascal also supports
separate compilation of modules.
 
M

Maarten Wiltink

Huh ? What reference ? :) No you didn't :)

"See the External Declarations entry in the Delphi help. Pay particular
attention to the $LINK compiler directive."

My baby nieces have a longer attention span, and they listen better, too.

Groetjes,
Maarten Wiltink
 
S

Skybuck Flying

Maarten Wiltink said:
"See the External Declarations entry in the Delphi help. Pay particular
attention to the $LINK compiler directive."

My baby nieces have a longer attention span, and they listen better, too.

Dude, really, I already know that part of the help file, you're boring me :D

$LINK directive is boring :D
 
M

Maarten Wiltink

Skybuck Flying said:
Dude, really, I already know that part of the help file, you're boring
me :D

$LINK directive is boring :D

"Dude", "really", the question wasn't if you had already read it. It was
if you were spouting nonsense or not when you claimed he didn't give you
a reference. Stop taking those pills from the spam ad and go back to the
ones the doctor gave you.

Groetjes,
Maarten Wiltink
 
S

Skybuck Flying

Maarten Wiltink said:
"Dude", "really", the question wasn't if you had already read it. It was
if you were spouting nonsense or not when you claimed he didn't give you
a reference. Stop taking those pills from the spam ad and go back to the
ones the doctor gave you.

The whole point ofcourse is that in C one doesn't need any link directives ?

Or maybe unless one counts the link directives in visual c's project file :D
 
N

Nicolai Hansen

As usual you think wrong. See the External Declarations entry in the Delphi
help. Pay particular attention to the $LINK compiler directive.

AFAIK (and as far as I could read from the help files :p) $LINK
doesn't do anything but link to a non-project file (and as the help
file says, to use with files of other languages, ie .o/.obj C files/VB
files).

The C compiler allows you to generate a kind of "open ended" file (the
object file) which is compiled but not linked. For example a file
called test.c

void MyMethod();

int main()
{
MyMethod();

return 0;
}

This will compile, this will generate an object file, but this will
not generate an executable. It will say something like "LINKER ERROR:
unsatisfied external "void MyMethod()" in file test.c".
At a later time you can then make a file test2.c

void MyMethod()
{
return;
}

compile this file, and link test.o with test2.o and generate test.exe.
Useful? ;-)

/Nic
 
S

Skybuck Flying

Nicolai Hansen said:
AFAIK (and as far as I could read from the help files :p) $LINK
doesn't do anything but link to a non-project file (and as the help
file says, to use with files of other languages, ie .o/.obj C files/VB
files).

The C compiler allows you to generate a kind of "open ended" file (the
object file) which is compiled but not linked. For example a file
called test.c

void MyMethod();

int main()
{
MyMethod();

return 0;
}

This will compile, this will generate an object file, but this will
not generate an executable. It will say something like "LINKER ERROR:
unsatisfied external "void MyMethod()" in file test.c".
At a later time you can then make a file test2.c

void MyMethod()
{
return;
}

compile this file, and link test.o with test2.o and generate test.exe.
Useful? ;-)

If it's usefull I don't know =D

But it is interesting :D
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top