Finding joy in coding Using Pascal programming language

Started by
43 comments, last by jms bc 10 years, 9 months ago

PASCAL writeln() procedure uses variable argument lists.

Advertisement

Presumably it must use a C-style calling convention for that then? (Another possibility is that the number/size of arguments is passed as a hidden parameter so that the called function can clean up the stack rather than the callee). EDIT: I'd have to look at the disassembly of the call to see what is going on in that case.

Anyway, that's the difference between pascal and C calling conventions (apart from the left to right parameter passing, again, it is easier to pass right to left if you use variable length argument lists, since the first argument is always bottom of the stack frame), and the reason for use in Win32 API was originally to save memory.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

There is no such language as C/C++ - yes, I know this point is sometimes pedantic, but it's important to distinguish when discussing something like pointers.

Can the OP clarify what he means by passing by value? I mean, passing strings and SDL_Surfaces by value would have the problem in C of copying large amounts of data - that's why C uses pointers.

C++ can do this by references - are you arguing against references and pointers? It can also handle this by copy-on-write, so passing by value doesn't necessarily copy data until required, but it's up to the classes/library to implement this.

How does Pascal pass information like strings around, or information to external libraries?

The SDL and WinAPI examples are C interfaces, not C++ ones. I guess it is a valid complaint that people often don't bother to write C++ interfaces, so you're still forced to deal with C-style interfaces and pointers in C++, but then I thought that it's harder to find out-of-the-box support for Pascal too? What do the same APIs for Pascal look like?

For the Qt example, the strings are passed by reference.

http://erebusrpg.sourceforge.net/ - Erebus, Open Source RPG for Windows/Linux/Android
http://conquests.sourceforge.net/ - Conquests, Open Source Civ-like Game for Windows/Linux

Pass parameters by reference as C++ mention is a language construct. But normaly is implemented with pointers. Pointers are references too.

Niklaus Wirth, the founder of PASCAL, defined the two possibilities to pass parameter by value, logicaly copying them onto the stack, or passing them by reference. He uses these two mechanisms for to (dis-)allow a function/procedure to change the passed parameters on the callers side. This behaviour of passing parameters by reference and this way makeing the changes to the parameter within a function/procedure visible to the caller has introduced the "side-effect".

Using pointers and their description as something that describe the location where the value resides makes it easier to understand side-effects. For the C-Language using pointers was the only way of change a value within a function and make it visible to the caller.

C++ introduced the reference with the same meaning and implementation but with the benefit not to stumble upon pointer arithmetics or with very unclean access to arrays of elements where only a single parameter was passed.

I do understand the reference in C++ but mostly use pointers because I am very familiar with that concept and always think in pointers.

AFAIK ANSI PASCAL has no modules concept. All code is put into a single file. And so you need no external libraries. Passing a string by value means copying to the stack. Needs a bit room on it.

I know some grey hairs that still use Delphi 7.

A few years ago you might envy the built-in extended real data type (10 bytes), and the progs always seemed to run faster than what you could get from msvc with similar effort.

The Four Horsemen of Happiness have left.

This topic is closed to new replies.

Advertisement