Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 10 Mar 2012 18:22:40 -0600 Message-ID: <4F5BF051.303D@mindspring.com> Date: Sat, 10 Mar 2012 19:22:41 -0500 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: i think i found References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 69 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.218.170 X-Trace: sv3-yrqYSwqa9/kuebxe7bj5dTvY6ShHnsLwMP07renh32tZexCF2rRs21qCBu3WfMc0XN9tbvs6q7ZTKwl!UYFXwJr2EjsYkkfpsQdz6fwElLRUCeCF+GxUCDETaM4L7bTtMc29XR2bb4ih+Ok1CpM1+nk8BXNz!XHsj3/R41AA= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2917 X-Received-Bytes: 3097 Xref: csiph.com comp.lang.c:18501 Barry Schwarz wrote: > > On Mar 9, 7:09 pm, j...@panix.com (Joe keane) wrote: > > How about this? > > > > int f(int x) > > { > > int a[2]; > > int *p; > > > > p = &a[0]; > > *p = 2; > > ++p; > > *p = 3; > > /* printf("%d %d\n", a[0], a[1]); */ > > } > > > > That pretty much has to work, right? > > No it does not. The function fails to return an int as promised in > the declaration. I don't remember whether this is undefined behavior > or a constraint violation. Prior to C99, these words: ISO/IEC 9899: 1990 6.6.6.4 The return statement A function may have any number of return statements, with and without expressions. If a return statement without an expression is executed, and the value of the function call is used by the caller, the behavior is undefined. Reaching the } that terminates a function is equivalent to executing a return statement without an expression. suggest that the use of the above function was defined in C90, as long as the code didn't use the return value. Both C99 and n1570, only have this much to say on this matter: A function may have any number of return statements. > > So what's the deal with arrays of arrays? > > Since your sample code does not have any arrays of arrays, we have no > idea what your question is. Did you perchance mean something like > > int f(int x) > { > int a[4][3]; > int (*p)[3]; > > p = &a[0]; > (*p)[1] = 2; > ++p; > (*p)[2] = 3; > /* printf("%d %d\n", a[0][1], a[1][2]); */ > return 0; > } I think that leaving the printf statement commented out is a little bit funny. -- pete