3

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:

  • using the {$MODE} directive
  • assign it to String type and print it.

So far, they are everything I could think about.

1 Answer 1

4

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}):

  1. External files are declared as parameters in the program statement.
  2. Files have associated ”buffer variables”.
  3. The procedures ”get” and ”put” operate on file buffer variables.
  4. […]

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.

  • Compile your code with fpc -Miso -Sr source.pas. Then the program parameter a becomes associated with A.TXT.
  • Or, specify file names on the command-line as parameters (in the appropriate order). This still requires compiling your code with 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

  1. generally speaking, in Pascal a list takes the form (a, b, c, …), and
  2. you are not limited to input/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: input and output. […]

Regardless of that, thank you; your (implicit) feedback is appreciated, and you are welcome to contribute yourself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.