On 6/30/2013 10:22 AM, Charles Mills wrote:
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.
Quibble away. There are a lot of variables; for example, using
pragma statements can change things. But genrally speaking I
believe this is true. I no longer have access to a z/OS system
to recreate my example, but some simple experiments should
suffice to demonstrate truth, either way.
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."
Whoops! Yes, you're right on that.
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).
Agree.
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.
Agree
My whole point was to address the assertion from an
earlier point in this thread that C invariably passes
arguments by reference.
As usual, the simple answer is 'it depends' and, as Shmuel
points out, the devil is in the details.
--
Kind regards,
-Steve Comstock
The Trainer's Friend, Inc.
303-355-2752
http://www.trainersfriend.com
* Special promotion: 15% off on all DB2 training classes
scheduled by September 1, taught by year end 2011
* Check out our entire DB2 curriculum at:
http://www.trainersfriend.com/DB2_and_VSAM_courses/DB2curric.htm
Charles
-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf
Of Steve Comstock
Sent: Saturday, June 29, 2013 7:55 AM
To: IBM-MAIN@LISTSERV.UA.EDU
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 lists...@listserv.ua.edu with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN