I'm new in programming with Pascal (forced to learn it by my school)
I've read this page and this page but still don't really understand about the "program parameter".
They are something like this
program prg_name(input, output, stdErr);
{^^^^^^^^^^^^^^^^^^^^^}
{What is this and how to use it}
But from this page, I just use this:
program prg_name(a, b, c);
And try to read from a, b, c.
Apparently, they are said to be "Command line arguments" in iriepascal (Here). But it does not work with FreePascal (version 3.2.2). And in FPC's wiki page, they only read from input.
So, can anyone explain to me what this means? Can I read/write to something else than just input, output and stdErr?
I've tried to search the Internet for something like "freepascal program parameter", "pascal program parameter", "pascal program keyword parameter" but can't find any useful document (except that one from irietools).
What I've also tried:
{$MODE} directiveString type and print it.So far, they are everything I could think about.
The Free Pascal Compiler’s Reference Guide states:
The program header is provided for backwards compatibility, and is ignored by the compiler.
Therefore, it has no significance to the program’s meaning1 and (for FPC) it can be omitted.
(If it is there, it has to be syntactically correct.)
Then, however, the Programmer’s Guide states with respect to {$mode ISO} (and also to {$mode extendedPascal}):
- External files are declared as parameters in the program statement.
- Files have associated ”buffer variables”.
- The procedures ”get” and ”put” operate on file buffer variables.
- […]
So then the program header can have significance.
The details have not found their way into the official documentation (yet), but the FPC’s wiki describes two methods.
fpc -Miso -Sr source.pas.
Then the program parameter a becomes associated with A.TXT.fpc -Miso source.pas.
(The ‑Miso can omitted if you place {$mode ISO} in your source code [before the program header].)1: In non-ISO modes the program name becomes reserved though and can be used in fully-qualified identifiers.
This behavior is actually implementation-defined. If I compile the following source code with the GPC – the GNU Pascal Compiler
program fileTest(foobar);
var
foobar: text;
begin
reset(foobar);
end.
and run it, I get the following prompt during execution:
Input file `foobar': /tmp/fileTest.pas
(The /tmp/fileTest.pas is my user input.)
There you do not have the automatic mapping command-line parameter → file name.
A different compiler might show a different behavior again, so you need to look up its documentation.
(And you cannot simply use Iriepascal documentation [or any other compiler’s documentation] for Delphi, FPC or GPC.)
I am (currently) the main contributor to the Pascal Programming WikiBook you referred to.
But from this page, I just use this:
program prg_name(a, b, c);And try to read from
a,b,c.
On “this page” the sentence
[…] This is a program parameter. In fact, it is a list. Here, it only contains one item, but the general form is
(a, b, c, d, e, …)and so on. […]
was merely meant to express that
(a, b, c, …), andinput/output.
This is emphasized in a following sentence:
[…] We will go into detail later on, but for now we need to know there are two special program parameters:
inputandoutput. […]
Regardless of that, thank you; your (implicit) feedback is appreciated, and you are welcome to contribute yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With