Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #18501

Re: i think i found

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> (permalink)
Date Sat, 10 Mar 2012 19:22:41 -0500
From pete <pfiland@mindspring.com>
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 <jje9kd$d14$1@reader1.panix.com> <ea3cda64-a914-4f34-ba2a-59df5fb9fc93@m13g2000yqi.googlegroups.com>
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

Show key headers only | View raw


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

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

i think i found jgk@panix.com (Joe keane) - 2012-03-10 01:09 +0000
  Re: i think i found Ian Collins <ian-news@hotmail.com> - 2012-03-10 14:23 +1300
  Re: i think i found nick_keighley_nospam@hotmail.com - 2012-03-10 03:13 -0800
  Re: i think i found Barry Schwarz <schwarz45@yahoo.com> - 2012-03-10 09:17 -0800
    Re: i think i found pete <pfiland@mindspring.com> - 2012-03-10 19:22 -0500
      Re: i think i found James Kuyper <jameskuyper@verizon.net> - 2012-03-10 20:14 -0500
        Re: i think i found pete <pfiland@mindspring.com> - 2012-03-10 21:59 -0500
      Re: i think i found jgk@panix.com (Joe keane) - 2012-03-12 17:29 +0000
    Re: i think i found jgk@panix.com (Joe keane) - 2012-03-11 19:35 +0000
      Re: i think i found Keith Thompson <kst-u@mib.org> - 2012-03-11 13:06 -0700
        Re: i think i found jgk@panix.com (Joe keane) - 2012-03-13 20:27 +0000
          Re: i think i found Keith Thompson <kst-u@mib.org> - 2012-03-13 15:25 -0700
            Re: i think i found jgk@panix.com (Joe keane) - 2012-03-14 23:34 +0000
              Re: i think i found Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-03-14 20:38 -0400
              Re: i think i found Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-15 18:03 -0700
                Re: i think i found jgk@panix.com (Joe keane) - 2012-03-17 17:34 +0000
                Re: i think i found Keith Thompson <kst-u@mib.org> - 2012-03-17 18:02 -0700
                Re: i think i found jgk@panix.com (Joe keane) - 2012-03-19 15:41 +0000
                Re: i think i found Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-21 05:52 -0700

csiph-web