Steve, are you sure?

> If you pass the name of a structure, the entire structure is passed in the 
> argument list

I would quibble with that depending on exactly what you mean.

> If you pass the name of any item preceded by an apostrophe the address of the 
> item is passed in the argument list

I think you mean "an ampersand."

> If you pass a character literal (e.g.: 'C'), the literal is placed into a 
> full word ...

This is integer promotion and is independent of function calls. The same would 
be true of, for example, comparing 'C' to an integer: int foo = 195; if (foo == 
'C') ... would compare true (assuming an EBCDIC environment).

For all of the above, the function prototype is the key. The function gets what 
it claims to want. The caller has to provide that, or something that the 
compiler or library can convert to that. It's not like the caller can decide 
whether to pass "the address of the item" or not. If the function is expecting 
the address of a character, then you must pass the address of a character (or 
something that you claim to be the address of a character) and the function 
will receive that, with no promotion to a fullword. The same sort of 
consideration is true for most of your assertions below.

Charles

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:[email protected]] On Behalf 
Of Steve Comstock
Sent: Saturday, June 29, 2013 7:55 AM
To: [email protected]
Subject: Re: Theology question: Parameter formats

Not entirely.

First, though, I'd like to question your assumption that if the address of a 
parameter is passed the subroutine will make a copy of the value. If an address 
is passed I would expect the subroutine to tie the address to a DSECT / based / 
linkage section (Assembler / PL/I / COBOL) structure, thus referencing the data 
without making a copy.

Passing arguments in C:

* Of course, there is interaction based on the prototype
   of the function declaration and how an argument is
   specified on the function call, but generally ...

* If you pass the name of a structure, the entire
   structure is passed in the argument list

* If you pass the name of any item preceded by an apostrophe
   the address of the item is passed in the argument list

   (This is true for structures and arrays and elementary items)

* If you pass the name of a pointer preceded by an asterisk,
   the value pointed at by the pointer is placed into the
   argument list

* If you pass a character literal (e.g.: 'C'), the literal
   is placed into a full word in the argument list, right
   justified, left filled with nulls

* If you pass a numeric literal or numeric expression, the
   expression is converted to the format indicated in the
   prototype and placed into the argument list

   (of course, the literal or expression must be such that
    such a conversion is possible; otherwise you get a
    compile error)

* A variable number of arguments may be passed using an
   ellipsis (...) in the function prototype

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to