Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Pointers, constant values Date: Fri, 16 Oct 2015 12:06:22 -0700 Organization: None to speak of Lines: 36 Message-ID: References: <5b2ab074-7644-4798-9b90-a3ae47e1f2b8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="25043"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/T38Kt6XCFQRJbDP5q9Pt+" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:kCmktXMGtQ3Ki1UEquUypYWdOSs= sha1:Eqx/ByVpnx+KufLF9mjzweyOzPc= Xref: csiph.com comp.lang.c:73057 supercat@casperkitty.com writes: > On Friday, October 16, 2015 at 10:25:16 AM UTC-5, Keith Thompson wrote: >> Not everyone will agree with this; some will argue that using the [] >> notation is a reminder that it points to an element of an array, not >> just a single int object. Which is a valid point -- but in my opinion >> the reminder that it's really a pointer is more valuable. > > How about, following along with the idea of "[static n]", how about adopting > the convention of using "TYPE *name" in cases where the parameter might > sometimes legitimately be null, and "TYPE name[]" in cases where the the > parameter could never legitimately be null. Using that convention... > > void process_things(THING *things, int n); > > would suggest that process_things(NULL, 0); would do nothing, while > > void process_things(THING things[], int n); > > would suggest that it must never be. [...] C already has a notation for asserting that a pointer parameter must be non-null: void process_things(THING things[static 1], int n); That's "asserting" in the sense that violating the assertion causes undefined behavior. Of course you can also add assert(things != NULL); if you like, or treat it as a run-time error, or whatever. -- Keith Thompson (The_Other_Keith) kst-u@mib.org 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"