Skip to main content

How to make compiler give error when parameter lists differ on call

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

Program a calls program b with 4 linkage parameters. Progam b is only using 3 parameters. Can this be  flagged  as an error at compile time?

Resolution:

To make this work code  a prototype copybook.  A sample of how to do this is attached.

To get the compiler to complain about incorrect parameters in a CALL statement, the compiler must first know what a  correct  CALL looks like. Supplying a CALL prototype does this.

CALL prototypes are supplied in a special format (usually implemented in a COPY file for the sake of reuse)

I have attached a demo to this note, the demo shows how to define CALL prototypes for user written programs. When you define a prototype you must define everything about it. The data types being passed,  the way the item is passed, even the size and usage clause needs to be defined in the prototype.  

Once the prototype definitions are in the copy file then the copy file needs to be included in the program that is going to be making the CALLs - BEFORE the Identification Division.

In the demo there are several files:

1)       demoproto.cpy  - the prototype definitions

2)       sprog1.cbl - This program attempts to call sprog2 using an incorrect number of parameters

3)       sprog1a.cbl - This program calls sprog2 using the correct number and type of parameters

4)       sprog2.cbl - a program called by sprog1 and sprog1a

5)       sprog3.cbl - a program called by sprog1a

If you compile

cob -xv sprog1.cbl sprog2.cbl

You will see the errors:

* Compiling sprog1.cbl

    52     call "sprog2" using inputa f-key arg-line.

*1058-E*********************************************                         **

**    Number of parameters is greater than in prototype

*1059-E*********************************************                         **

**    Parameter is not consistent with that defined in prototype

Attachments:

demoproto.tar

Old KB# 2077

0 replies

Be the first to reply!