Re: [C++] Functions Opinion
From: Leor Zolman (leor_at_bdsoft.com)
Date: 01/09/04
- Next message: Ryan Lee: "online literatures"
- Previous message: Arthur J. O'Dwyer: "Re: [C] functions and 2D arrays?"
- In reply to: jeffc: "Re: [C++] Functions Opinion"
- Next in thread: jeffc: "Re: [C++] Functions Opinion"
- Reply: jeffc: "Re: [C++] Functions Opinion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 09 Jan 2004 03:58:46 GMT
On Thu, 8 Jan 2004 17:23:02 -0500, "jeffc" <nobody@nowhere.com> wrote:
>
>"Leor Zolman" <leor@bdsoft.com> wrote in message
>news:i16rvv04ce3pfa6i1d0d5r49l522auntr2@4ax.com...
>> >
>> >> Declarations can be in the form of a prototype, or they can be part of
>> >> the function definition itself. Redundancy is OK; you can have one (or
>> >> more) declarations for the same function so long as they con't
>> >> contradict each other. But only one function _definition_ is allowed.
>> >> As long as the compiler sees that definition before it sees the first
>> >> call to the function, you can get away without a prototype.
>> >
>> >That is:
>> >A functions definition acts as its own prototype, or as we say:
>> >a definition is a declaration at the same time.
>>
>> I've always used the term "prototype" to mean a C++ function
>> declaration that's *not* part of its definition. Scanning through the
>> Standard, I could not find the term "function prototype" actually
>> defined anywhere (the closest term used being "function prototype
>> scope"), so I guess folks are free to use the term however they want .
>> But since we agree that a definition is also a declaration, it seems
>> more useful to reserve the word "prototype" for the way I meant it...
>
>That sounds reasonable.
>
I thought so. I still do, in fact, but the truth is somewhat more
convoluted than I'd hoped it would be. I just spent 20 minutes on the
phone with Dan Saks to try to sort it out. Here's the scoop:
It is true that the C++ Standard never defines the term "prototype",
even though it uses it (and not just within the phrase "function
prototype scope", which _is_ defined in the C++ Standard). My question
to Dan was, "where is the term _prototype_ defined?"
His answer: "Did you check the C Standard?"
Duh.
In the C Standard, a "prototype" is defined as a function declaration
with type information between the parentheses (I'm paraphrasing,
because I don't actually own a copy of the C Standard [*blush*]). And
that, taken literally, means that a function definition _in C_ having
type info between the parentheses would qualify as a "prototyped
function definition". I'd have to admit that it would therefore be
reasonable to say "the function has a prototype", even though there
may be no "non-defining declaration" in scope for that function..
In that sense, my lobbying for the term "prototype" to be used to mean
"non-defining declaration" would be inconsistent with what the _C_
standard defines a "prototype" to be. So we can't use that term for C
and be consistent with the C Standard.
But what about when talking about C++? Now this is the part I
like...sort of. The C++ language has absolutely no use for the concept
of "non-prototyped function definitions". [Believe it or not, in C the
following function would _not_ be considered prototyped, even after
its definition:
int foo()
{ return 1; }
That "non-protoyped" status affects the implicit widening (or
non-widening) of arguments in calls to that function, even though
those arguments end up getting ignored by the function. Strange but
true.] Because, in C++, _all_ function declarations (including, of
course, definitions) convey complete information about their
parameters (or lack of them), the C++ Standard simply has no need to
explicitly define the term "prototype", or "prototyped function
definition/declaration". As a consequence, _in_C++_, one is truly free
to adopt the term "prototype" to mean "non-defining function
declaration", the way I was hoping to be able to get away with. The
problem, as Dan carefully pointed out, is that the word can't have the
same meaning in the context of _C_.
Whew.
I'm going to bed.
-leor
Leor Zolman
BD Software
leor@bdsoft.com
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
- Next message: Ryan Lee: "online literatures"
- Previous message: Arthur J. O'Dwyer: "Re: [C] functions and 2D arrays?"
- In reply to: jeffc: "Re: [C++] Functions Opinion"
- Next in thread: jeffc: "Re: [C++] Functions Opinion"
- Reply: jeffc: "Re: [C++] Functions Opinion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|