Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. |
| Date | 2014-06-11 08:35 -0700 |
| Organization | None to speak of |
| Message-ID | <lnsinblarr.fsf@nuthaus.mib.org> (permalink) |
| References | (1 earlier) <C-20140609212332@ram.dialup.fu-berlin.de> <lnioo9n7gz.fsf@nuthaus.mib.org> <ln58jv$b7s$1@speranza.aioe.org> <lna99ln32t.fsf@nuthaus.mib.org> <ln8t99$1l1$1@usenet.stanford.edu> |
Seungbeom Kim <musiphil@bawi.org> writes:
> On 2014-06-09 15:14, Keith Thompson wrote:
>> The () form in a declaration says that the function takes a fixed but
>> unspecified number and type(s) of arguments. In a definition, it says
>> that the function has no parameters, but it still provides a declaration
>> with the above meaning.
>
> Can you explain what you mean by the second sentence above?
> If it says that the function has no parameters, doesn't it constitute a
> declaration that says the same thing? If there exists something that says
> a function has no parameters but that is not a declaration, what is it?
>
> The only relevant part I could find in the standard was N1570:6.7.6.3/14:
> "An empty list in a function declarator that is part of a definition
> of that function specifies that the function has no parameters", but
> it doesn't seem to imply that it still provides a declaration that
> allows anything but no parameters.
Strange as it seems, the empty parentheses in
void foo() { /* ... */ }
specify that foo has no parameters, but they don't specify that it takes
no arguments. (This strangeness is easily avoided by using prototypes
consistently.)
N1570 6.9.1p7:
The declarator in a function definition specifies the name of the
function being defined and the identifiers of its parameters. If the
declarator includes a parameter type list, the list also specifies
the types of all the parameters; such a declarator also serves as a
function prototype for later calls to the same function in the same
translation unit. If the declarator includes an identifier list,
the types of the parameters shall be declared in a following
declaration list.
The second sentence says that a definition that includes a parameter
type list, such as:
void foo(void) { ... }
provides a prototype, equivalent to:
void foo(void);
which means that, if that definition is visible, any call that passes
one or more arguments is a constraint violation. Without a parameter
type list, no such prototype is provided, and an incorrect call has
undefined behavior (and needn't be diagnosed).
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Christos Kokaliaris <chrisk.msor@gmail.com> - 2014-06-09 12:12 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Christos Kokaliaris <chrisk.msor@gmail.com> - 2014-06-09 12:41 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Barry Schwarz <schwarzb@dqel.com> - 2014-06-09 13:16 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Tim Rentsch <txr@alumni.caltech.edu> - 2014-06-12 09:08 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. raltbos@xs4all.nl (Richard Bos) - 2014-06-12 16:35 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Tim Rentsch <txr@alumni.caltech.edu> - 2014-06-13 07:27 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2014-06-14 00:13 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Tim Rentsch <txr@alumni.caltech.edu> - 2014-06-16 07:07 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2014-06-16 20:04 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Tim Rentsch <txr@alumni.caltech.edu> - 2014-06-17 08:56 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. raltbos@xs4all.nl (Richard Bos) - 2014-06-16 12:53 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Tim Rentsch <txr@alumni.caltech.edu> - 2014-06-16 08:00 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Kaz Kylheku <kaz@kylheku.com> - 2014-06-16 16:01 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Tim Rentsch <txr@alumni.caltech.edu> - 2014-06-17 08:24 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. raltbos@xs4all.nl (Richard Bos) - 2014-06-18 10:50 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Tim Rentsch <txr@alumni.caltech.edu> - 2014-06-26 19:07 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Kaz Kylheku <kaz@kylheku.com> - 2014-06-09 19:51 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2014-06-09 20:15 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Christos Kokaliaris <chrisk.msor@gmail.com> - 2014-06-09 13:21 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Keith Thompson <kst-u@mib.org> - 2014-06-09 13:39 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-06-09 21:23 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Kaz Kylheku <kaz@kylheku.com> - 2014-06-09 21:43 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-06-10 00:17 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. "BartC" <bc@freeuk.com> - 2014-06-10 11:13 +0100
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Keith Thompson <kst-u@mib.org> - 2014-06-10 07:38 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. raltbos@xs4all.nl (Richard Bos) - 2014-06-10 10:23 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Dr Nick <nospam-4@temporary-address.org.uk> - 2014-06-10 18:55 +0100
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Keith Thompson <kst-u@mib.org> - 2014-06-09 15:14 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-06-10 00:21 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. James Kuyper <jameskuyper@verizon.net> - 2014-06-09 21:37 -0400
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Keith Thompson <kst-u@mib.org> - 2014-06-10 07:45 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Tim Rentsch <txr@alumni.caltech.edu> - 2014-06-11 01:32 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Cal Dershowitz <Cal@example.invalid> - 2014-06-09 23:14 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. raltbos@xs4all.nl (Richard Bos) - 2014-06-10 10:14 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2014-06-10 22:06 +0300
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. raltbos@xs4all.nl (Richard Bos) - 2014-06-11 16:16 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Kaz Kylheku <kaz@kylheku.com> - 2014-06-11 16:47 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2014-06-11 20:50 +0300
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. raltbos@xs4all.nl (Richard Bos) - 2014-06-11 16:16 +0000
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2014-06-10 08:23 -0600
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Keith Thompson <kst-u@mib.org> - 2014-06-10 10:12 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Tim Rentsch <txr@alumni.caltech.edu> - 2014-06-12 08:39 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Robert Wessel <robertwessel2@yahoo.com> - 2014-06-12 12:30 -0500
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Seungbeom Kim <musiphil@bawi.org> - 2014-06-10 23:34 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Tim Rentsch <txr@alumni.caltech.edu> - 2014-06-11 00:35 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Keith Thompson <kst-u@mib.org> - 2014-06-11 08:35 -0700
Re: C Programming Language 2nd Ed, Exercise 1.9 and 1.12, Solution suggestion. Kaz Kylheku <kaz@kylheku.com> - 2014-06-11 15:49 +0000
csiph-web