Forum > General

[SOLVED] Information needed on how to use program parameters

(1/2) > >>

furious programming:
Sometimes I meet with the extended structure of the program header with a defined list of untyped parameters. I have never used such a structure and I still do not do it, because I have no idea how it is used. For example:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Test(Foo, Bar, Input, Output);begin end.
What are the parameters of Foo and Bar and other? What type are they? How to use them?

I did not find any information in the documentation on this subject — the 16.1 Programs page does not contain any description, although the diagram shows a variation of the header with parameters. However, in the description is this fragment:


--- Quote ---The program header is provided for backwards compatibility, and is ignored by the compiler.
--- End quote ---

If the program header is supported due to backward compatibility, then it should be possible to use these parameters, since the declaration of such a header does not cause a compilation error. But how?

I found an explanation of the purpose of these parameters in the manual from IrieTools — What are program parameters? — however, the examples given do not work correctly in the FPC (with {$OBJFPC} mode), although they compile without errors.

Does anyone know anything about this?

rvk:
Not sure what you are asking exactly.

But if you want to use command line parameter you need to use ParamCount and ParamStr.
See http://wiki.freepascal.org/Command_line_parameters_and_environment_variables


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;{$mode objfpc}{$H+}var  I: Integer;begin  WriteLn('Program: ', ParamStr(0));  for I := 1 to ParamCount do    WriteLn('Param ', I, ': ', ParamStr(I));end.

lucamar:
When the FPC Reference says:


--- Quote from: Free Pascal Reference Guide ---The program header is provided for backwards compatibility, and is ignored by the compiler.
--- End quote ---

It means exactly that: the header is parsed and accepted but nothing  is done with it. It's allowed, but ignored.

Note that the same is true of Turbo Pascal and Delphi (IIRC), and other Pascal compilers: they allow you to specify the full header but do nothing with it.

For those that do something about it, it's the equivalent of doing (if they are file types):

--- Code: ---Assign(first, ParamStr[1]);
Assign(second, ParamStr[2]);
{...etc...}
--- End code ---

ETA
This what the standard has to say about it:

--- Quote from: ISO/IEC 7185 :1990(E) ---The identifier of the program-heading shall be the program name . It shall have no significance within the program . The identifiers contained by the program-parameter-list shall be distinct and shall be designated program-parameters . Each program-parameter shall have a defining-point as a variable-identifier for the region that is the program-block . The binding of the variables denoted by the program-parameters to entities external to the program shall be implementation-dependent, except if the variable possesses a file-type in which case the binding shall be implementation-defined.
--- End quote ---

furious programming:

--- Quote from: rvk on March 11, 2019, 04:53:39 pm ---Not sure what you are asking exactly.
--- End quote ---

I'm asking exactly how to use the parameters defined in the program header and whether it is possible at all. I use ParamCount and ParamStr functions on a daily basis, but I'm curious if those headers can be used as well. Just curious.


--- Quote from: lucamar on March 11, 2019, 04:59:13 pm ---It means exactly that: the header is parsed and accepted but nothing  is done with it. It's allowed, but ignored.
--- End quote ---

Since the program will compile, but it will not work as it is assumed, it's strange backwards compatibility… :D

lucamar:

--- Quote from: furious programming on March 11, 2019, 05:14:19 pm ---Since the program will compile, but it will not work as it is assumed, it's strange backwards compatibility… :D

--- End quote ---

Maybe it works only in some modes? ISO? To be honest,  I don't really know. But yes it's a strange kind of "compatibility" :)

Navigation

[0] Message Index

[#] Next page

Go to full version