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


Groups > comp.lang.c > #75202

Re: Funny C Program

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Funny C Program
Date 2015-11-06 20:07 -0500
Organization Self
Message-ID <563D4EE4.1030209@verizon.net> (permalink)
References <e1367c64-92c8-4c2e-abb1-0ebf2c27bce7@googlegroups.com> <24250e2c-bcdd-4425-a730-433ffc6f89e0@googlegroups.com>

Show all headers | View raw


On 11/06/2015 07:40 PM, jimzhou001@gmail.com wrote:
> Actually I have another question,"Is 'int monk[101]={0};' really legal?Or is it necessary for us to initialize the array by a loop?"I did meet the problem.Anyone can explain it?Thanks.If interested,follow the link for this question:http://jimzhou001.blogspot.de/2015/11/funny-c-programzhishen-lu-eating_78.html

No, a loop is not necessary. For any object of aggregate type (array or
struct - 6.2.5p21), you can provide an initializer that explicitly
initializes only part of the object (6.7.9p21). If you do so, then all
of the parts not explicitly initialized will be handled the same as
objects with static storage duration that have no explicit initializer:
they are set to zero, if they have arithmetic type, or to a null
pointer, if they have a pointer type (6.7.9p10). This also applies if
you initialize a character array with a string literal that is shorter
than the array:

    char long_array[80] = "short string";

long_array[i] == '\0' for all values of 'i' from 12 to 79.

In C90, the only way to provide an incomplete initializer was to provide
an initializer for the first N elements of an array, or the first N
members of a struct. In C99, designated initializers were added
(6.7.9p6,7), which allow sparse initialization. The declarations:

    int monk[101]={[50]=-1;};
    struct tm then = {.tm_year = 50;};

are essentially equivalent to:

    int monk[101] = {0};
    monk[50] = -1;
    struct tm middle = {0};
    middle.tm_year = 50;

with one key exception: if either 'monk' or 'middle' had been declared
'const', the assignment statements above would be constraint violations,
but the corresponding designated initializers are not.

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


Thread

Funny C Program jimzhou001@gmail.com - 2015-11-03 17:54 -0800
  Re: Funny C Program bartekltg <bartekltg@gmail.com> - 2015-11-04 05:28 +0100
    Re: Funny C Program Richard Heathfield <rjh@cpax.org.uk> - 2015-11-04 07:12 +0000
      Re: Funny C Program bartekltg <bartekltg@gmail.com> - 2015-11-04 13:25 +0100
        Re: Funny C Program bartekltg <bartekltg@gmail.com> - 2015-11-04 13:52 +0100
          Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 06:36 -0800
    Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 02:28 -0800
      Re: Funny C Program bartekltg <bartekltg@gmail.com> - 2015-11-04 13:25 +0100
    Re: Funny C Program Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-04 19:07 -0800
      Re: Funny C Program bartekltg <bartekltg@gmail.com> - 2015-11-05 09:48 +0100
        Re: Funny C Program Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-05 06:08 -0800
  Re: Funny C Program Richard Heathfield <rjh@cpax.org.uk> - 2015-11-04 07:04 +0000
    Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 02:33 -0800
      Re: Funny C Program Richard Heathfield <rjh@cpax.org.uk> - 2015-11-04 10:57 +0000
        Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 03:46 -0800
          Re: Funny C Program luser droog <luser.droog@gmail.com> - 2015-11-04 10:46 -0800
            Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 15:14 -0800
  Re: Funny C Program brian.oakley@stonybrook.edu - 2015-11-04 12:37 -0800
    Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 15:30 -0800
  Funny C Program jimzhou001@gmail.com - 2015-11-06 16:40 -0800
    Re: Funny C Program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-07 01:04 +0000
      Re: Funny C Program Keith Thompson <kst-u@mib.org> - 2015-11-06 17:12 -0800
        Re: Funny C Program jimzhou001@gmail.com - 2015-11-06 18:47 -0800
          Re: Funny C Program James Kuyper <jameskuyper@verizon.net> - 2015-11-07 11:24 -0500
            Re: Funny C Program jimzhou001@gmail.com - 2015-11-07 16:21 -0800
              Re: Funny C Program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-08 00:46 +0000
              Re: Funny C Program James Kuyper <jameskuyper@verizon.net> - 2015-11-07 19:56 -0500
                Re: Funny C Program jimzhou001@gmail.com - 2015-11-07 19:08 -0800
                Re: Funny C Program James Kuyper <jameskuyper@verizon.net> - 2015-11-08 10:58 -0500
                Re: Funny C Program James Kuyper <jameskuyper@verizon.net> - 2015-11-12 13:31 -0500
                Re: Funny C Program Keith Thompson <kst-u@mib.org> - 2015-11-12 11:59 -0800
                Re: Funny C Program jimzhou001@gmail.com - 2015-11-17 23:00 -0800
                Re: Funny C Program jimzhou001@gmail.com - 2015-11-18 00:12 -0800
                Re: Funny C Program Keith Thompson <kst-u@mib.org> - 2015-11-18 09:01 -0800
                Re: Funny C Program jimzhou001@gmail.com - 2015-11-17 23:00 -0800
    Re: Funny C Program James Kuyper <jameskuyper@verizon.net> - 2015-11-06 20:07 -0500

csiph-web