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


Groups > comp.lang.c > #11315 > unrolled thread

initialization of local static variable

Started by"V.Subramanian, India" <subramanian100in@yahoo.com>
First post2011-10-06 23:33 -0700
Last post2011-10-08 00:08 -0400
Articles 20 on this page of 63 — 24 participants

Back to article view | Back to comp.lang.c


Contents

  initialization of local static variable "V.Subramanian, India" <subramanian100in@yahoo.com> - 2011-10-06 23:33 -0700
    Re: initialization of local static variable pete <pfiland@mindspring.com> - 2011-10-07 02:51 -0400
    Re: initialization of local static variable "BartC" <bc@freeuk.com> - 2011-10-07 10:44 +0100
    Re: initialization of local static variable China Blue Corn Chips <chine.bleu@yahoo.com> - 2011-10-07 03:03 -0700
      Re: initialization of local static variable "BartC" <bc@freeuk.com> - 2011-10-07 11:33 +0100
        Re: initialization of local static variable jt@toerring.de (Jens Thoms Toerring) - 2011-10-07 11:11 +0000
          Re: initialization of local static variable "BartC" <bc@freeuk.com> - 2011-10-07 12:51 +0100
            Re: initialization of local static variable jt@toerring.de (Jens Thoms Toerring) - 2011-10-07 15:56 +0000
              Re: initialization of local static variable Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-07 20:29 +0100
                Re: initialization of local static variable jacob navia <jacob@spamsink.net> - 2011-10-07 21:38 +0200
                  Re: initialization of local static variable Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-07 21:16 +0100
                    Re: initialization of local static variable jacob navia <jacob@spamsink.net> - 2011-10-07 22:22 +0200
                      Re: initialization of local static variable jt@toerring.de (Jens Thoms Toerring) - 2011-10-07 22:25 +0000
                        Re: initialization of local static variable jacob navia <jacob@spamsink.net> - 2011-10-08 00:40 +0200
                          Re: initialization of local static variable Ian Collins <ian-news@hotmail.com> - 2011-10-08 11:56 +1300
                            Re: initialization of local static variable jacob navia <jacob@spamsink.net> - 2011-10-08 01:53 +0200
                              Re: initialization of local static variable Jens Gustedt <jens.gustedt@loria.fr> - 2011-10-09 23:04 +0200
                              Re: initialization of local static variable Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-10-10 11:54 -0500
                                Re: initialization of local static variable Ike Naar <ike@sverige.freeshell.org> - 2011-10-10 17:41 +0000
                                  Re: initialization of local static variable Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-10-10 17:35 -0500
                          Re: initialization of local static variable jt@toerring.de (Jens Thoms Toerring) - 2011-10-08 00:02 +0000
                            Re: initialization of local static variable "BartC" <bc@freeuk.com> - 2011-10-08 01:26 +0100
                              Re: initialization of local static variable "Philip Lantz" <prl@canterey.us> - 2011-10-08 03:01 -0700
                  Re: initialization of local static variable "BartC" <bc@freeuk.com> - 2011-10-07 21:42 +0100
                  Re: initialization of local static variable China Blue Corn Chips <chine.bleu@yahoo.com> - 2011-10-07 16:25 -0700
                    Re: initialization of local static variable jacob navia <jacob@spamsink.net> - 2011-10-08 01:51 +0200
                      Re: initialization of local static variable China Blue Corn Chips <chine.bleu@yahoo.com> - 2011-10-07 18:21 -0700
                  Re: initialization of local static variable Nobody <nobody@nowhere.com> - 2011-10-08 15:36 +0100
                    Re: initialization of local static variable Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-08 22:06 +0100
                      Re: initialization of local static variable Nobody <nobody@nowhere.com> - 2011-10-09 05:35 +0100
                        Re: initialization of local static variable Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-09 09:25 +0100
                        Re: initialization of local static variable "io_x" <a@b.c.invalid> - 2011-10-09 11:00 +0200
                          Re: initialization of local static variable Barry Schwarz <schwarzb@dqel.com> - 2011-10-09 10:56 -0700
                            Re: initialization of local static variable James Kuyper <jameskuyper@verizon.net> - 2011-10-09 14:30 -0400
                              Re: initialization of local static variable Barry Schwarz <schwarzb@dqel.com> - 2011-10-09 21:43 -0700
                            Re: initialization of local static variable "io_x" <a@b.c.invalid> - 2011-10-10 19:08 +0200
                              Re: initialization of local static variable Geoff <geoff@invalid.invalid> - 2011-10-10 16:16 -0700
                                Re: initialization of local static variable Ike Naar <ike@iceland.freeshell.org> - 2011-10-10 23:22 +0000
                                Re: initialization of local static variable James Kuyper <jameskuyper@verizon.net> - 2011-10-10 20:40 -0400
                              Re: initialization of local static variable Barry Schwarz <schwarzb@dqel.com> - 2011-10-10 20:54 -0700
                                Re: initialization of local static variable "io_x" <a@b.c.invalid> - 2011-10-11 18:45 +0200
                                  Re: initialization of local static variable "io_x" <a@b.c.invalid> - 2011-10-11 18:51 +0200
                                    Re: initialization of local static variable Barry Schwarz <schwarzb@dqel.com> - 2011-10-11 18:52 -0700
                                      Re: initialization of local static variable "io_x" <a@b.c.invalid> - 2011-10-12 08:49 +0200
                                  Re: initialization of local static variable "io_x" <a@b.c.invalid> - 2011-10-11 19:48 +0200
                                    Re: initialization of local static variable Barry Schwarz <schwarzb@dqel.com> - 2011-10-11 21:25 -0700
                                      Re: initialization of local static variable "io_x" <a@b.c.invalid> - 2011-10-12 08:48 +0200
                                        Re: initialization of local static variable "io_x" <a@b.c.invalid> - 2011-10-12 08:54 +0200
                                          Re: initialization of local static variable pete <pfiland@mindspring.com> - 2011-10-12 20:55 -0400
                                  Re: initialization of local static variable Barry Schwarz <schwarzb@dqel.com> - 2011-10-11 18:52 -0700
                                Re: initialization of local static variable "io_x" <a@b.c.invalid> - 2011-10-11 19:55 +0200
                                  Re: initialization of local static variable Keith Thompson <kst-u@mib.org> - 2011-10-11 11:24 -0700
                                    Re: initialization of local static variable Keith Thompson <kst-u@mib.org> - 2011-10-11 12:47 -0700
                                    Re: initialization of local static variable "io_x" <a@b.c.invalid> - 2011-10-12 08:49 +0200
              Re: initialization of local static variable Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 16:09 -0800
            Re: initialization of local static variable China Blue Corn Chips <chine.bleu@yahoo.com> - 2011-10-07 16:06 -0700
              Re: initialization of local static variable Seebs <usenet-nospam@seebs.net> - 2011-10-12 22:25 +0000
                Re: initialization of local static variable "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2011-10-13 07:09 -0700
                  Re: initialization of local static variable Seebs <usenet-nospam@seebs.net> - 2011-10-17 17:21 +0000
                Re: initialization of local static variable Joe Wright <joewwright@comcast.net> - 2011-10-14 14:27 -0400
            Re: initialization of local static variable Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-08 00:03 -0400
              Re: initialization of local static variable China Blue Corn Chips <chine.bleu@yahoo.com> - 2011-10-08 01:27 -0700
            Re: initialization of local static variable Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-08 00:08 -0400

Page 3 of 4 — ← Prev page 1 2 [3] 4  Next page →


#11530

From"io_x" <a@b.c.invalid>
Date2011-10-11 18:45 +0200
Message-ID<4e9471e5$0$1389$4fafbaef@reader1.news.tin.it>
In reply to#11496
"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio 
news:0ec797paci7qkqbrlb6d3426imcml9h0a5@4ax.com...
> On Mon, 10 Oct 2011 19:08:56 +0200, "io_x" <a@b.c.invalid> wrote:
>
>>
>>"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>>news:von397t5o2d6tg0r9utiv49is6k7vukl9v@4ax.com...
>>> On Sun, 9 Oct 2011 11:00:30 +0200, "io_x" <a@b.c.invalid> wrote:
>>>
>>> snip
>>>
>>>>so this for a is not 'a' initialization:
>>>>
>>>>void  f(void){int  a;  ....}
>>>>
>>>>because no one sets "the *initial* value to"  'a'
>>>>even if f() is called
>>>
>>> It is not an initialization because initialization requires an
>>> assignment expression which is clearly not present (6.7.8).
>>
>>so for you the global variable  "vii"
>>...
>>static int vii;
>>...
>>is not initilizated...
>>for me it is initializated to 0 even if there is no "vii=number;"
>
> I'm sorry; I didn't realize you wanted to play language lawyer.  In
> that case, I have to ask: what difference does it make if vii is
> global or has block scope?

Buon Giorno
if "int vii;" and "vii" is gloabal
[ie "int vii;"  out of all functions or procedure]
the compiler i use assign the initial value 0
to that variable [vii==0]

if "int vii;" is in a function or procedure
or in its "block scope" than "vii" has one value
i don't know in the range of int...
at last on what rememeber

i remember K&R speak about that too


[toc] | [prev] | [next] | [standalone]


#11531

From"io_x" <a@b.c.invalid>
Date2011-10-11 18:51 +0200
Message-ID<4e947374$0$1385$4fafbaef@reader1.news.tin.it>
In reply to#11530
"io_x" <a@b.c.invalid> ha scritto nel messaggio 
news:4e9471e5$0$1389$4fafbaef@reader1.news.tin.it...
>
> "Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio 
> news:0ec797paci7qkqbrlb6d3426imcml9h0a5@4ax.com...
>> On Mon, 10 Oct 2011 19:08:56 +0200, "io_x" <a@b.c.invalid> wrote:
>>
>>>
>>>"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>>>news:von397t5o2d6tg0r9utiv49is6k7vukl9v@4ax.com...
>>>> On Sun, 9 Oct 2011 11:00:30 +0200, "io_x" <a@b.c.invalid> wrote:
>>>>
>>>> snip
>>>>
>>>>>so this for a is not 'a' initialization:
>>>>>
>>>>>void  f(void){int  a;  ....}
>>>>>
>>>>>because no one sets "the *initial* value to"  'a'
>>>>>even if f() is called
>>>>
>>>> It is not an initialization because initialization requires an
>>>> assignment expression which is clearly not present (6.7.8).
>>>
>>>so for you the global variable  "vii"
>>>...
>>>static int vii;
>>>...
>>>is not initilizated...
>>>for me it is initializated to 0 even if there is no "vii=number;"
>>
>> I'm sorry; I didn't realize you wanted to play language lawyer.  In
>> that case, I have to ask: what difference does it make if vii is
>> global or has block scope?
>
> Buon Giorno
> if "int vii;" and "vii" is gloabal
> [ie "int vii;"  out of all functions or procedure]
> the compiler i use assign the initial value 0
> to that variable [vii==0]

that vii=0
as say here someone: first of the first main() instruction


> if "int vii;" is in a function or procedure
> or in its "block scope" than "vii" has one value
> i don't know in the range of int...
> at last on what rememeber

and this ["vii" has one start value i don't know]
always, each time i call the function

> i remember K&R speak about that too
>

[toc] | [prev] | [next] | [standalone]


#11552

FromBarry Schwarz <schwarzb@dqel.com>
Date2011-10-11 18:52 -0700
Message-ID<1ds997dsrik2qrg98r87fidpbafnulct40@4ax.com>
In reply to#11531
On Tue, 11 Oct 2011 18:51:47 +0200, "io_x" <a@b.c.invalid> wrote:

>
>"io_x" <a@b.c.invalid> ha scritto nel messaggio 
>news:4e9471e5$0$1389$4fafbaef@reader1.news.tin.it...
>>
>> "Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio 
>> news:0ec797paci7qkqbrlb6d3426imcml9h0a5@4ax.com...
>>> On Mon, 10 Oct 2011 19:08:56 +0200, "io_x" <a@b.c.invalid> wrote:
>>>
>>>>
>>>>"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>>>>news:von397t5o2d6tg0r9utiv49is6k7vukl9v@4ax.com...
>>>>> On Sun, 9 Oct 2011 11:00:30 +0200, "io_x" <a@b.c.invalid> wrote:
>>>>>
>>>>> snip
>>>>>
>>>>>>so this for a is not 'a' initialization:
>>>>>>
>>>>>>void  f(void){int  a;  ....}
>>>>>>
>>>>>>because no one sets "the *initial* value to"  'a'
>>>>>>even if f() is called
>>>>>
>>>>> It is not an initialization because initialization requires an
>>>>> assignment expression which is clearly not present (6.7.8).
>>>>
>>>>so for you the global variable  "vii"
>>>>...
>>>>static int vii;
>>>>...
>>>>is not initilizated...
>>>>for me it is initializated to 0 even if there is no "vii=number;"
>>>
>>> I'm sorry; I didn't realize you wanted to play language lawyer.  In
>>> that case, I have to ask: what difference does it make if vii is
>>> global or has block scope?
>>
>> Buon Giorno
>> if "int vii;" and "vii" is gloabal
>> [ie "int vii;"  out of all functions or procedure]
>> the compiler i use assign the initial value 0
>> to that variable [vii==0]
>
>that vii=0
>as say here someone: first of the first main() instruction

What main()?  The only function in your message was f().

>
>
>> if "int vii;" is in a function or procedure
>> or in its "block scope" than "vii" has one value
>> i don't know in the range of int...
>> at last on what rememeber
>
>and this ["vii" has one start value i don't know]
>always, each time i call the function

A static variable always contains the last value it was assigned or
its default initialization if it has not been assigned.  It's your
code.  If you don't know what value, if any, you assigned it, we can't
help.

-- 
Remove del for email

[toc] | [prev] | [next] | [standalone]


#11556

From"io_x" <a@b.c.invalid>
Date2011-10-12 08:49 +0200
Message-ID<4e9537b2$0$1383$4fafbaef@reader1.news.tin.it>
In reply to#11552
"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
news:1ds997dsrik2qrg98r87fidpbafnulct40@4ax.com...
> On Tue, 11 Oct 2011 18:51:47 +0200, "io_x" <a@b.c.invalid> wrote:
>
>>
>>"io_x" <a@b.c.invalid> ha scritto nel messaggio
>>news:4e9471e5$0$1389$4fafbaef@reader1.news.tin.it...
>>>
>>> "Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>>> news:0ec797paci7qkqbrlb6d3426imcml9h0a5@4ax.com...
>>>> On Mon, 10 Oct 2011 19:08:56 +0200, "io_x" <a@b.c.invalid> wrote:
>>>>
>>>>>
>>>>>"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>>>>>news:von397t5o2d6tg0r9utiv49is6k7vukl9v@4ax.com...
>>>>>> On Sun, 9 Oct 2011 11:00:30 +0200, "io_x" <a@b.c.invalid> wrote:
>>>>>>
>>>>>> snip
>>>>>>
>>>>>>>so this for a is not 'a' initialization:
>>>>>>>
>>>>>>>void  f(void){int  a;  ....}
>>>>>>>
>>>>>>>because no one sets "the *initial* value to"  'a'
>>>>>>>even if f() is called
>>>>>>
>>>>>> It is not an initialization because initialization requires an
>>>>>> assignment expression which is clearly not present (6.7.8).
>>>>>
>>>>>so for you the global variable  "vii"
>>>>>...
>>>>>static int vii;
>>>>>...
>>>>>is not initilizated...
>>>>>for me it is initializated to 0 even if there is no "vii=number;"
>>>>
>>>> I'm sorry; I didn't realize you wanted to play language lawyer.  In
>>>> that case, I have to ask: what difference does it make if vii is
>>>> global or has block scope?
>>>
>>> Buon Giorno
>>> if "int vii;" and "vii" is gloabal
>>> [ie "int vii;"  out of all functions or procedure]
>>> the compiler i use assign the initial value 0
>>> to that variable [vii==0]
>>
>>that vii=0
>>as say here someone: first of the first main() instruction
>
> What main()?  The only function in your message was f().

if there is a f() and it is a C program there will be a main()



[toc] | [prev] | [next] | [standalone]


#11533

From"io_x" <a@b.c.invalid>
Date2011-10-11 19:48 +0200
Message-ID<4e9480db$0$1377$4fafbaef@reader2.news.tin.it>
In reply to#11530
"io_x" <a@b.c.invalid> ha scritto nel messaggio
news:4e9471e5$0$1389$4fafbaef@reader1.news.tin.it...
>
> "Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
> news:0ec797paci7qkqbrlb6d3426imcml9h0a5@4ax.com...
>> On Mon, 10 Oct 2011 19:08:56 +0200, "io_x" <a@b.c.invalid> wrote:
>>
>>>
>>>"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>>>news:von397t5o2d6tg0r9utiv49is6k7vukl9v@4ax.com...
>>>> On Sun, 9 Oct 2011 11:00:30 +0200, "io_x" <a@b.c.invalid> wrote:
>>>>
>>>> snip
>>>>
>>>>>so this for a is not 'a' initialization:
>>>>>
>>>>>void  f(void){int  a;  ....}
>>>>>
>>>>>because no one sets "the *initial* value to"  'a'
>>>>>even if f() is called
>>>>
>>>> It is not an initialization because initialization requires an
>>>> assignment expression which is clearly not present (6.7.8).
>>>
>>>so for you the global variable  "vii"
>>>...
>>>static int vii;
>>>...
>>>is not initilizated...
>>>for me it is initializated to 0 even if there is no "vii=number;"
>>
>> I'm sorry; I didn't realize you wanted to play language lawyer.  In
>> that case, I have to ask: what difference does it make if vii is
>> global or has block scope?
>
> Buon Giorno
> if "int vii;" and "vii" is gloabal
> [ie "int vii;"  out of all functions or procedure]
> the compiler i use assign the initial value 0
> to that variable [vii==0]
>
> if "int vii;" is in a function or procedure
> or in its "block scope" than "vii" has one value
> i don't know in the range of int...
> at last on what rememeber
>
> i remember K&R speak about that too

yes i find K&R seems to speak about
static variable initialization
[global or in a function or block as "static int etc;"]
in A10.2
"Se nell'unità di traduzione non compaiono definizioni dell'oggetto,
tutte le definizioni sperimentali relative a esso diventano
un'unica definizione con inizializzatore 0"

or something about that



[toc] | [prev] | [next] | [standalone]


#11554

FromBarry Schwarz <schwarzb@dqel.com>
Date2011-10-11 21:25 -0700
Message-ID<sk4a975ev9pcnaa5mm3jh6khhcokkud9i4@4ax.com>
In reply to#11533
On Tue, 11 Oct 2011 19:48:10 +0200, "io_x" <a@b.c.invalid> wrote:

>
>"io_x" <a@b.c.invalid> ha scritto nel messaggio
>news:4e9471e5$0$1389$4fafbaef@reader1.news.tin.it...
>>
>> "Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>> news:0ec797paci7qkqbrlb6d3426imcml9h0a5@4ax.com...
>>> On Mon, 10 Oct 2011 19:08:56 +0200, "io_x" <a@b.c.invalid> wrote:
>>>
>>>>
>>>>"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>>>>news:von397t5o2d6tg0r9utiv49is6k7vukl9v@4ax.com...
>>>>> On Sun, 9 Oct 2011 11:00:30 +0200, "io_x" <a@b.c.invalid> wrote:
>>>>>
>>>>> snip
>>>>>
>>>>>>so this for a is not 'a' initialization:
>>>>>>
>>>>>>void  f(void){int  a;  ....}
>>>>>>
>>>>>>because no one sets "the *initial* value to"  'a'
>>>>>>even if f() is called
>>>>>
>>>>> It is not an initialization because initialization requires an
>>>>> assignment expression which is clearly not present (6.7.8).
>>>>
>>>>so for you the global variable  "vii"
>>>>...
>>>>static int vii;
>>>>...
>>>>is not initilizated...
>>>>for me it is initializated to 0 even if there is no "vii=number;"
>>>
>>> I'm sorry; I didn't realize you wanted to play language lawyer.  In
>>> that case, I have to ask: what difference does it make if vii is
>>> global or has block scope?
>>
>> Buon Giorno
>> if "int vii;" and "vii" is gloabal
>> [ie "int vii;"  out of all functions or procedure]
>> the compiler i use assign the initial value 0
>> to that variable [vii==0]
>>
>> if "int vii;" is in a function or procedure
>> or in its "block scope" than "vii" has one value
>> i don't know in the range of int...
>> at last on what rememeber
>>
>> i remember K&R speak about that too
>
>yes i find K&R seems to speak about
>static variable initialization
>[global or in a function or block as "static int etc;"]
>in A10.2
>"Se nell'unità di traduzione non compaiono definizioni dell'oggetto,
>tutte le definizioni sperimentali relative a esso diventano
>un'unica definizione con inizializzatore 0"

Since A10.2 talks about external declarations, why would you even
bring it up in this discussion?  You conveniently left of the
introductory sentence to your quote: "For objects with external
linkage ..."  It has absolutely nothing to do with the default
initialization of a variable declared with the static storage-class.
This is just another red herring.

-- 
Remove del for email

[toc] | [prev] | [next] | [standalone]


#11555

From"io_x" <a@b.c.invalid>
Date2011-10-12 08:48 +0200
Message-ID<4e9537ab$0$1383$4fafbaef@reader1.news.tin.it>
In reply to#11554
"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
news:sk4a975ev9pcnaa5mm3jh6khhcokkud9i4@4ax.com...
> On Tue, 11 Oct 2011 19:48:10 +0200, "io_x" <a@b.c.invalid> wrote:
>
>>
>>"io_x" <a@b.c.invalid> ha scritto nel messaggio
>>news:4e9471e5$0$1389$4fafbaef@reader1.news.tin.it...
>>>
>>> "Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>>> news:0ec797paci7qkqbrlb6d3426imcml9h0a5@4ax.com...
>>>> On Mon, 10 Oct 2011 19:08:56 +0200, "io_x" <a@b.c.invalid> wrote:
>>>>
>>>>>
>>>>>"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>>>>>news:von397t5o2d6tg0r9utiv49is6k7vukl9v@4ax.com...
>>>>>> On Sun, 9 Oct 2011 11:00:30 +0200, "io_x" <a@b.c.invalid> wrote:
>>>>>>
>>>>>> snip
>>>>>>
>>>>>>>so this for a is not 'a' initialization:
>>>>>>>
>>>>>>>void  f(void){int  a;  ....}
>>>>>>>
>>>>>>>because no one sets "the *initial* value to"  'a'
>>>>>>>even if f() is called
>>>>>>
>>>>>> It is not an initialization because initialization requires an
>>>>>> assignment expression which is clearly not present (6.7.8).
>>>>>
>>>>>so for you the global variable  "vii"
>>>>>...
>>>>>static int vii;
>>>>>...
>>>>>is not initilizated...
>>>>>for me it is initializated to 0 even if there is no "vii=number;"
>>>>
>>>> I'm sorry; I didn't realize you wanted to play language lawyer.  In
>>>> that case, I have to ask: what difference does it make if vii is
>>>> global or has block scope?
>>>
>>> Buon Giorno
>>> if "int vii;" and "vii" is gloabal
>>> [ie "int vii;"  out of all functions or procedure]
>>> the compiler i use assign the initial value 0
>>> to that variable [vii==0]
>>>
>>> if "int vii;" is in a function or procedure
>>> or in its "block scope" than "vii" has one value
>>> i don't know in the range of int...
>>> at last on what rememeber
>>>
>>> i remember K&R speak about that too
>>
>>yes i find K&R seems to speak about
>>static variable initialization
>>[global or in a function or block as "static int etc;"]
>>in A10.2
>>"Se nell'unità di traduzione non compaiono definizioni dell'oggetto,
>>tutte le definizioni sperimentali relative a esso diventano
>>un'unica definizione con inizializzatore 0"
>
> Since A10.2 talks about external declarations,

in how i read global variables are "about external declarations"
in few i know there are 2 type of variable
automatic [the one diclared in block]
register
extern    [all the others, global, etc]

so 10.2 is ok for global variables

than i find the 4.9 in K&R2 that says

"In assenza di un'inizializzazione esplicita, il C garantisce che
le variabili esterne e quelle static vengano inizializzati a zero;
le variabili automatiche e quelle register, invece, hanno valori
iniziali indefiniti (sono, cioè, sporche)"

so i have no doubit
than
paragraph 4.4 show the difference between declaration and definition
declaration==show only the type of variable [e.g  exetern int vii;]
definition ==show the type of the variable + reserve memory [int vii;]
initialization== put in a varible one value first of the first use

> why would you even
> bring it up in this discussion?  You conveniently left of the
> introductory sentence to your quote: "For objects with external
> linkage ..."  It has absolutely nothing to do with the default
> initialization of a variable declared with the static storage-class.
> This is just another red herring.
>
> -- 
> Remove del for email


[toc] | [prev] | [next] | [standalone]


#11558

From"io_x" <a@b.c.invalid>
Date2011-10-12 08:54 +0200
Message-ID<4e9538e9$0$1378$4fafbaef@reader2.news.tin.it>
In reply to#11555
"io_x" <a@b.c.invalid> ha scritto nel messaggio 
news:4e9537ab$0$1383$4fafbaef@reader1.news.tin.it...

Buon Giorno

> in how i read global variables are "about external declarations"
> in few i know there are 2 type of variable

in few i know are at last 3 types of varibles

 automatic [the diclared in block]
 register  [the diclared in block]
 extern    [all the others, global, etc]

>
> so 10.2 is ok for global variables

[toc] | [prev] | [next] | [standalone]


#11602

Frompete <pfiland@mindspring.com>
Date2011-10-12 20:55 -0400
Message-ID<4E963709.406@mindspring.com>
In reply to#11558
io_x wrote:
 
>  automatic [the diclared in block]
>  register  [the diclared in block]
>  extern    [all the others, global, etc]

As of C99, there are three kinds of storage duration:

1    automatic
2    static
3    allocated

-- 
pete

[toc] | [prev] | [next] | [standalone]


#11551

FromBarry Schwarz <schwarzb@dqel.com>
Date2011-10-11 18:52 -0700
Message-ID<l5s997t68a8qsaalbe9e9uk65rrks7fbaa@4ax.com>
In reply to#11530
On Tue, 11 Oct 2011 18:45:07 +0200, "io_x" <a@b.c.invalid> wrote:

>
>"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio 
>news:0ec797paci7qkqbrlb6d3426imcml9h0a5@4ax.com...
>> On Mon, 10 Oct 2011 19:08:56 +0200, "io_x" <a@b.c.invalid> wrote:
>>
>>>
>>>"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio
>>>news:von397t5o2d6tg0r9utiv49is6k7vukl9v@4ax.com...
>>>> On Sun, 9 Oct 2011 11:00:30 +0200, "io_x" <a@b.c.invalid> wrote:
>>>>
>>>> snip
>>>>
>>>>>so this for a is not 'a' initialization:
>>>>>
>>>>>void  f(void){int  a;  ....}
>>>>>
>>>>>because no one sets "the *initial* value to"  'a'
>>>>>even if f() is called
>>>>
>>>> It is not an initialization because initialization requires an
>>>> assignment expression which is clearly not present (6.7.8).
>>>
>>>so for you the global variable  "vii"
>>>...
>>>static int vii;
>>>...
>>>is not initilizated...
>>>for me it is initializated to 0 even if there is no "vii=number;"
>>
>> I'm sorry; I didn't realize you wanted to play language lawyer.  In
>> that case, I have to ask: what difference does it make if vii is
>> global or has block scope?
>
>Buon Giorno
>if "int vii;" and "vii" is gloabal
>[ie "int vii;"  out of all functions or procedure]
>the compiler i use assign the initial value 0
>to that variable [vii==0]
>
>if "int vii;" is in a function or procedure
>or in its "block scope" than "vii" has one value

All scalar variables have only one value.  

The question I asked you was what is different about the
initialization of static int vii when it is at global scope compared
to when it is within a function?

>i don't know in the range of int...
>at last on what rememeber

What does the range of  values for an int have to do with how it is
initialized by default?  Why are you introducing extraneous and
irrelevant side issues into the discussion?

-- 
Remove del for email

[toc] | [prev] | [next] | [standalone]


#11535

From"io_x" <a@b.c.invalid>
Date2011-10-11 19:55 +0200
Message-ID<4e948277$0$1375$4fafbaef@reader2.news.tin.it>
In reply to#11496
"Barry Schwarz" <schwarzb@dqel.com> ha scritto nel messaggio 
news:0ec797paci7qkqbrlb6d3426imcml9h0a5@4ax.com...
> On Mon, 10 Oct 2011 19:08:56 +0200, "io_x" <a@b.c.invalid> wrote:
>
> I'm sorry; I didn't realize you wanted to play language lawyer.  In

if i would play "language lawyer" i would suggest to semplify
[abbreviate registers names, use some chars for represent jumps, etc]
notation of assembly and use that

each algo when has to deal with arrays and numbers
has to have one base written in assembly
it is no matter what language what the remain of that algo
is written
 

[toc] | [prev] | [next] | [standalone]


#11539

FromKeith Thompson <kst-u@mib.org>
Date2011-10-11 11:24 -0700
Message-ID<lny5wrtmid.fsf@nuthaus.mib.org>
In reply to#11535
"io_x" <a@b.c.invalid> writes:
[...]
> each algo when has to deal with arrays and numbers
> has to have one base written in assembly
> it is no matter what language what the remain of that algo
> is written

That is complete nonsense.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#11541

FromKeith Thompson <kst-u@mib.org>
Date2011-10-11 12:47 -0700
Message-ID<lnty7ftimz.fsf@nuthaus.mib.org>
In reply to#11539
Keith Thompson <kst-u@mib.org> writes:
> "io_x" <a@b.c.invalid> writes:
> [...]
>> each algo when has to deal with arrays and numbers
>> has to have one base written in assembly
>> it is no matter what language what the remain of that algo
>> is written
>
> That is complete nonsense.

I suppose I should expand on that.

It's perfectly reasonable for algorithms dealing with arrays and numbers
to be expressed in some high-level language, or even in pseudo-code (if
the point is to communicate the algorithm to a human reader).  There is
rarely any need (or even advantage) to expressing part of such an
algorithm in assembly language.

There are some cases where assembly language can be useful to speed up
portions of an algorithm, but that's far from universal -- and it comes
with substantial costs in clarity and portability.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#11557

From"io_x" <a@b.c.invalid>
Date2011-10-12 08:49 +0200
Message-ID<4e9537c4$0$1386$4fafbaef@reader1.news.tin.it>
In reply to#11539
"Keith Thompson" <kst-u@mib.org> ha scritto nel messaggio
news:lny5wrtmid.fsf@nuthaus.mib.org...
> "io_x" <a@b.c.invalid> writes:
> [...]
>> each algo when has to deal with arrays and numbers
>> has to have one base written in assembly
>> it is no matter what language what the remain of that algo
>> is written
>
> That is complete nonsense.

your hll are good in use jumps[goto], stack,
arrays and numbers less than assembly...
it will be a nonsense but is what i see

> -- 
> Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
> "We must do something.  This is something.  Therefore, we must do this."
>    -- Antony Jay and Jonathan Lynn, "Yes Minister"


[toc] | [prev] | [next] | [standalone]


#16143

FromTim Rentsch <txr@alumni.caltech.edu>
Date2012-01-24 16:09 -0800
Message-ID<kfnhazkej7m.fsf@x-alumni2.alumni.caltech.edu>
In reply to#11330
jt@toerring.de (Jens Thoms Toerring) writes:

> BartC <bc@freeuk.com> wrote:
>> >> (I'm assuming p_first is re-initialised on each entry to the function.)
>> >
>> > No, 'p_first', being a static variable, is initialized exactly
>> > once when the program is loaded - at least that's how I would
>> > tend to interpret 3.1.2.4 in C89:
>
>> I tried this:
>
>> int a=1901;
>
>> void testfn(void) {
>>   static int b=a;
>>   printf("A, B = %d, %d\n",a,b);
>> }
>
>> - int main(void) {
>> -  testfn();
>> -  a=2901;
>> -  testfn();
>> - }
>
>> [hyphens added to avoid weird formatting issues in Windows Mail]
>
>> Which worked as expected, with lccwin32 compiler (b is assigned the value 
>> of a on each entry to the function).
>
> That, for me, would be absolutely unexpected since then the
> 'static' qualifier on 'b' would have no effect at all, it
> would behave exactly the same as if you would have written
>
>     int b = a;
>
>> On other, presumably more compliant compilers, this initialisation of b 
>> wasn't allowed.
>>
>> However the behaviour allowed by lccwin32 is more 
>> intuitive and more useful. (There is nothing after all to stop you writing:
>
>>   static int b; b=a;
>
>> which would have the same effect. So why not the convenience of having it 
>> all in one statement?)
>
> As I said, I would be rather surprised by this behaviou since I'm
> used to rely on static variables to be initialized once and then
> never again. Thus for me
>
>    static int b = a;
>
> (which doesn't work as long a isn't a constant expression) and
>
>    static int b;
>    b = a;
>
> are two rather different things. If 'a' is a constant expression
> then 'b' should be set once to it the first time the function is
> called and then retain any value it has at the end of the func-
> tion.
>
> Consider for example code like this you will find quite often:
>
> void foo( ) {
>     static int is_uninitialized = 1;
>     if ( ! is_uninitialized ) {
>          initialize_something( );
>          is_uninitialized = 0;
>     }
>     ...
> }
>
> Rather obviously, 'is_uninitialized' is meant to ensure that
> initialize_something() is called only once, the first time the
> function is called. Having it re-initialized to 1 every time
> the function is called would break a lot of existing code...
>
> But then the lccwin32 compiler allows something that isn't
> defined by the standard (initialization with a non-constant
> expression) and for that situation it could bend the rules
> in whatever way it wants - [snip]

Yes it can, _provided_ it issues the required diagnostic.

[toc] | [prev] | [next] | [standalone]


#11361

FromChina Blue Corn Chips <chine.bleu@yahoo.com>
Date2011-10-07 16:06 -0700
Message-ID<chine.bleu-87499F.16060607102011@news.eternal-september.org>
In reply to#11322
In article <j6mp4b$h3d$1@dont-email.me>, "BartC" <bc@freeuk.com> wrote:

>   static int b; b=a;

An intrepid programmer can program in Fortran no matter what language they use.

-- 
Celle est une langue.     |   With the nutty taste of wild hickory nuts.
C'est francais           /|\              I'm whoever you want me to be.
et tres, tres sexuel.    \|/         Annoying Usenet one post at a time.
- China Azul              |            At least I can stay in character.

[toc] | [prev] | [next] | [standalone]


#11601

FromSeebs <usenet-nospam@seebs.net>
Date2011-10-12 22:25 +0000
Message-ID<slrnj9c4it.2bj5.usenet-nospam@guild.seebs.net>
In reply to#11361
On 2011-10-07, China Blue Corn Chips <chine.bleu@yahoo.com> wrote:
> In article <j6mp4b$h3d$1@dont-email.me>, "BartC" <bc@freeuk.com> wrote:
>>   static int b; b=a;

> An intrepid programmer can program in Fortran no matter what
> language they use.

I recently spent quite a while tracking down a bug.

What finally revealed to me what was happening was:

	printf("%f\n", 3.0);
which, of course, yielded
	0.000000

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

[toc] | [prev] | [next] | [standalone]


#11621

From"christian.bau" <christian.bau@cbau.wanadoo.co.uk>
Date2011-10-13 07:09 -0700
Message-ID<523a818b-379a-453a-b30a-c215b85eda70@n18g2000vbv.googlegroups.com>
In reply to#11601
On Oct 12, 11:25 pm, Seebs <usenet-nos...@seebs.net> wrote:

> I recently spent quite a while tracking down a bug.
>
> What finally revealed to me what was happening was:
>
>         printf("%f\n", 3.0);
> which, of course, yielded
>         0.000000

We want to know details.

[toc] | [prev] | [next] | [standalone]


#11823

FromSeebs <usenet-nospam@seebs.net>
Date2011-10-17 17:21 +0000
Message-ID<slrnj9ncs5.1qcj.usenet-nospam@guild.seebs.net>
In reply to#11621
On 2011-10-13, christian.bau <christian.bau@cbau.wanadoo.co.uk> wrote:
> On Oct 12, 11:25?pm, Seebs <usenet-nos...@seebs.net> wrote:
>> I recently spent quite a while tracking down a bug.

>> What finally revealed to me what was happening was:
[...]
> We want to know details.

Okay, this one is a bit of-topic, but part of the curse of C is that
sometimes what's going wrong ISN'T portable.

What was submitted to me was a bug report that some half-baked test of
POSIX functionality was failing on some embedded targets running Linux.

There's a bit of a spoiler in the previous post, but I'll just present this
as is.

Okay, the basic test as written was that the application creates a bunch
of stuff, including malloced memory, static variables, environment variables,
and so on.  Then it calls fork().

	DIGRESSION:  fork() is a UNIXism.  What you need to know is that
	this is the Unixy way to make new processes.  After a successful
	call to fork(), you have two copies of your program.  It doesn't
	load a different program; it just duplicates the current running
	program's memory space and state.  The system call returns 0 if
	you're in the child process, and the new process's process ID (which
	is greater than zero) if you're in the parent.  (Or -1 if it failed.)

After this, the child process then checks that all the values are the same
as they were in the parent.  Well.  The test of the malloced object fails.
Asked the testers for more detail, and they reported that if they run
the compiler on this test case directly, it works.  So I got asked to stare
at it some more.

Lemme quote you, approximately, the code in question.  I quote this because
it's totally irrelevant, but it's just awkward enough to make you wonder
whether it's really irrelevant:

	void *malloced

	malloced = (void *) malloc(sysconf(_SC_PAGESIZE));

	*(double *) malloced = 2.3;

	[...]
	if (*(double *) malloced != 2.3) {
		/* error here */
	}

(sysconf(_SC_PAGESIZE) turns out to be 4096).

Okay, was there a prototype for malloc in scope?  Yes there was.  Was
sysconf(_SC_PAGESIZE) yielding meaningful results?  Yup.  Okay, so next
up I came up with "some stupid floating point exactness bug", so I tried
2.125, and later 3.

I extracted the test program's build instructions (not trivial, the build
script hid them), extracted the other files it #included, and so on.
Eventually got a reproducer.  After a bit more testing, I got to the
following conclusion:  It was "-O2" breaking it.  If I compiled without
optimization, it ran fine.

Okay, now what?

1.  Make "malloced" a double *, allocate sizeof(double) space for it.
No change.
2.  Change it to 3.0 instead of 2.3.  No change.
3.  printf("%f\n", *malloced) => yields 3.000000.
4.  ... ooookay, then.  Let's try printing the value "*malloced != 3.0".
Sure enough, that's 1.
5.  Precision problems?  Print %a.  Get 1.8p+1.  Well, that didn't help.

So, after a bit more, I finally decide to try something crazy:

6.  printf("%f\n", 3.0);

That yields... 0.000000.  AH-HAH!

Now you see the marble in the oatmeal.  We've been assuming that the malloced
memory changed value somehow, but what if the thing it was COMPARED to changed
value?  Well.  At -O2, it turns out, the compiler notices that there's more
than once incidence of "3.0" in the source code, and combines them into a
single constant.  In a floating point register.

The actual problem:

Apparently, under some circumstances, programs which do not contain any
identifiable floating point operations do not get marked as needing their
floating point registers saved on process context switch.  Or properly
copied into a child process.  The actual problem is that a program which
doesn't contain any real floating point operations is relying on a register
which the kernel doesn't realize it should be saving, apparently.  I hand
the bug to the kernel team with my analysis, and a day or so later someone
backports a fix from another kernel branch that handles this case.

This isn't especially C-related, but this gets to the kind of thing that
I find to be one of the harder areas of C debugging; learning what *kinds* of
things are happening once optimizers are involved, and also remembering that
on a modern machine, the chances are quite good that your program has been
removed from the CPU entirely and put back later several times a second, or
more, during ordinary operation.

We tend to have this view of "the state of the machine", but it's a convenient
fiction.  There is no machine, there is no state.  Heck, modern x86 CPUs
don't actually execute x86 code, in general, they translate it at execution
time into a completely different set of microcode so they can execute it
out of order.

As always, there is a tension between the drive to know how things really
work, and the need to remember that in practice you don't really know how
they work because the model is still just a fiction you made up to let you
model something.

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

[toc] | [prev] | [next] | [standalone]


#11684

FromJoe Wright <joewwright@comcast.net>
Date2011-10-14 14:27 -0400
Message-ID<KcSdnWzIasVA4wXTnZ2dnUVZ_uidnZ2d@giganews.com>
In reply to#11601
On 10/12/2011 18:25, Seebs wrote:
> On 2011-10-07, China Blue Corn Chips<chine.bleu@yahoo.com>  wrote:
>> In article<j6mp4b$h3d$1@dont-email.me>, "BartC"<bc@freeuk.com>  wrote:
>>>    static int b; b=a;
>
>> An intrepid programmer can program in Fortran no matter what
>> language they use.
>
> I recently spent quite a while tracking down a bug.
>
> What finally revealed to me what was happening was:
>
> 	printf("%f\n", 3.0);
> which, of course, yielded
> 	0.000000
>
> -s
Hmm. I get 3.000000

-- 
Joe Wright
"If you rob Peter to pay Paul you can depend on the support of Paul."

[toc] | [prev] | [next] | [standalone]


Page 3 of 4 — ← Prev page 1 2 [3] 4  Next page →

Back to top | Article view | comp.lang.c


csiph-web