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: kandr2 question |
| Date | 2012-10-30 16:13 -0700 |
| Organization | None to speak of |
| Message-ID | <ln7gq7r1sc.fsf@nuthaus.mib.org> (permalink) |
| References | <k6phhi$kuq$1@dont-email.me> |
"Bill Cunningham" <nospam@nspam.invalid> writes:
> ยง1.9 page 29 has this function.
>
> int getline (char s[], int lim)
>
> Unless I'm missing something here to pass an array shoudn't that first
> parameter be char *s ?
It depends on what you mean by "should".
The rest of this thread indicates that you're aware that this:
int getline (char s[], int lim)
and this:
int getline (char *s, int lim)
are equivalent. This is implied by N1370 6.7.6.3 paragraph 7, or by the
corresponding paragraph in earlier versions or drafts of the C standard.
Apparently you were wondering about this as a style issue, though your
original question gave no hint of that (and nobody is going to assume
that you understand the language issue).
Personally, I dislike using array notation for pointer parameters;
in my opinion it obfuscates the fact that the parameter is really
a pointer. But there are sound arguments for using it. If I write:
void func(char *s);
the intent could be either that s points to a single object of type
char, or that s points to the first element of an array of one or
more char elements. Using array notation:
void func(char s[]);
can make it clear to the reader that it's intended to point to the
first element of an array. (I'd rather express this distinction
in a comment rather than using language syntax.) Furthermore, C99
added features that let you express additional information between
the square brackets. This:
void func(char s[42]);
requires s to point to the first element of an array of *at least*
42 elements. (This requirement is imposed on the caller, and it's
not enforced by the compiler; if you violate it, your program's
behavior is undefined.)
The standard itself uses array notation when defining the
two-parameter definition of main:
int main(int argc, char *argv[]) { /* ... */ }
Again, I prefer to write:
int main(int argc, char **argv) { /* ... */ }
It's interesting to note that the standard *doesn't* use array
notation for the <string.h> functions:
size_t strlen(const char *s);
even though s must point to the first element of an array. This is
arguably a slight inconsistency in the standard, but I don't think
it's worth worrying about.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"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
kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 17:41 -0500
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 14:48 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 17:50 -0500
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 14:56 -0700
Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 15:01 -0700
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:07 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:12 -0500
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:15 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:25 -0500
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:27 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:59 -0500
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:29 -0800
Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 15:30 -0700
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:36 -0700
Re: kandr2 question Kenneth Brody <kenbrody@spamcop.net> - 2012-10-31 14:15 -0400
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:04 -0500
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:07 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:09 -0500
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:13 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:30 -0500
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:50 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 19:28 -0500
Re: kandr2 question Lew Pitcher <lpitcher@teksavvy.com> - 2012-10-30 19:39 -0400
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 19:50 -0500
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:45 -0800
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:43 -0800
Re: kandr2 question Kenneth Brody <kenbrody@spamcop.net> - 2012-10-31 14:21 -0400
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:43 -0800
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:40 -0800
Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 15:31 -0700
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:36 -0700
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:37 -0800
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:07 -0500
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:10 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:47 -0500
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:52 -0700
Re: kandr2 question "BartC" <bc@freeuk.com> - 2012-10-30 22:08 +0000
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:11 -0700
Re: kandr2 question James Kuyper <jameskuyper@verizon.net> - 2012-10-30 18:36 -0400
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:44 -0500
Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:53 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 19:06 -0500
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 19:12 -0500
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:49 -0800
Re: kandr2 question Old Wolf <oldwolf@inspire.net.nz> - 2012-11-11 14:37 -0800
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:27 -0800
Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 15:00 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:18 -0500
Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 16:13 -0700
Re: kandr2 question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-30 23:31 +0000
Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 17:45 -0700
Re: kandr2 question Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2012-10-31 05:43 -0700
Re: kandr2 question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-31 13:33 +0000
Re: kandr2 question James Kuyper <jameskuyper@verizon.net> - 2012-10-31 10:27 -0400
Re: kandr2 question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-31 16:11 +0000
Re: kandr2 question Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2012-11-07 14:53 -0800
Re: kandr2 question James Kuyper <jameskuyper@verizon.net> - 2012-10-31 10:38 -0400
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 19:39 -0500
Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 17:51 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 13:47 -0500
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:55 -0800
Re: kandr2 question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-31 19:48 +0200
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:52 -0800
Re: kandr2 question hormelfree@gmail.com - 2012-11-10 11:23 -0800
Re: kandr2 question "BartC" <bc@freeuk.com> - 2012-10-31 01:56 +0000
Re: kandr2 question "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-10-30 18:44 -0700
Re: kandr2 question Barry Schwarz <schwarz45@yahoo.com> - 2012-10-30 20:32 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 13:52 -0500
Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-31 11:20 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 14:37 -0500
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 14:40 -0500
Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-31 12:18 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 15:29 -0500
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 16:56 -0500
Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-31 15:05 -0700
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-01 13:11 -0500
Re: kandr2 question Barry Schwarz <schwarz45@yahoo.com> - 2012-10-31 21:44 -0700
Re: kandr2 question Ike Naar <ike@sverige.freeshell.org> - 2012-11-01 09:34 +0000
Re: kandr2 question Barry Schwarz <schwarzb@dqel.com> - 2012-11-01 12:13 -0700
Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 07:04 -0800
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-01 15:26 -0500
Re: kandr2 question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-11-01 17:56 +0200
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-01 13:14 -0500
Re: kandr2 question SG <sgesemann@gmail.invalid> - 2012-10-31 20:14 +0100
Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 20:04 -0500
csiph-web