Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Premature optimization is the root of all evil. -- D. E. Knuth


devel / comp.lang.c / Re: some observation about declaration in loop

SubjectAuthor
* some observation about declaration in loopfir
+* Re: some observation about declaration in loopBen
|`* Re: some observation about declaration in loopfir
| +- Re: some observation about declaration in loopAndrey Tarasevich
| +* Re: some observation about declaration in loopArnold Ziffel
| |`* Re: some observation about declaration in loopBen
| | `* Re: some observation about declaration in loopfir
| |  `* Re: some observation about declaration in loopRichard Damon
| |   +* Re: some observation about declaration in loopBarry Schwarz
| |   |+* Re: some observation about declaration in loopSams Lara
| |   ||`- Re: some observation about declaration in loopBarry Schwarz
| |   |+* Re: some observation about declaration in loopKeith Thompson
| |   ||`* Re: some observation about declaration in loopRichard Damon
| |   || `* Re: some observation about declaration in loopMichael Bäuerle
| |   ||  `* Re: some observation about declaration in loopKeith Thompson
| |   ||   `- Re: some observation about declaration in loopMichael Bäuerle
| |   |`* Re: some observation about declaration in loopfir
| |   | `- Re: some observation about declaration in loopfir
| |   `- Re: some observation about declaration in loopAndrey Tarasevich
| +* Re: some observation about declaration in loopBen
| |`- Re: some observation about declaration in loopfir
| `* Re: some observation about declaration in loopLori Fairhead
|  `* Re: some observation about declaration in loopKeith Thompson
|   `* Re: some observation about declaration in loopLori Fairhead
|    `- Re: some observation about declaration in loopKeith Thompson
+* Re: some observation about declaration in loopAndrey Tarasevich
|`* Re: some observation about declaration in loopfir
| `* Re: some observation about declaration in loopfir
|  +- Re: some observation about declaration in loopAndrey Tarasevich
|  `* Re: some observation about declaration in loopArnold Ziffel
|   +* Re: some observation about declaration in loopfir
|   |`* Re: some observation about declaration in loopfir
|   | `- Re: some observation about declaration in loopArnold Ziffel
|   `- Re: some observation about declaration in loopJack Lemmon
+* Re: some observation about declaration in loopChristian Hanné
|`- Re: some observation about declaration in loopfir
+* Re: some observation about declaration in loopbart c
|`- Re: some observation about declaration in loopfir
`- Re: some observation about declaration in loopJohn Bode

Pages:12
some observation about declaration in loop

<194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21383&group=comp.lang.c#21383

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:625:b0:441:1578:620b with SMTP id a5-20020a056214062500b004411578620bmr5554913qvx.126.1650674573644;
Fri, 22 Apr 2022 17:42:53 -0700 (PDT)
X-Received: by 2002:a05:622a:1356:b0:2f1:f997:7857 with SMTP id
w22-20020a05622a135600b002f1f9977857mr5369001qtk.50.1650674573460; Fri, 22
Apr 2022 17:42:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Apr 2022 17:42:53 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.152; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.152
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
Subject: some observation about declaration in loop
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 23 Apr 2022 00:42:53 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 18
 by: fir - Sat, 23 Apr 2022 00:42 UTC

may seem funny but i tend to always not remember how declaration of in in loop behaves (though im not c newb for sure)

for(int i=0; i<10; i++)
{
int x = 10;
x++;
printf("\n %d", x);
}

for(int i=0; i<10; i++)
{
static int x = 10;
x++;
printf("\n %d", x);
}

those two behaves quite differently (though i test in c++ mode must say but i assume in standard c it is the same)

are you able to justify/explain the way it behaves is the right way?

Re: some observation about declaration in loop

<87czh81tmt.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21384&group=comp.lang.c#21384

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.lang.c
Subject: Re: some observation about declaration in loop
Date: Sat, 23 Apr 2022 02:22:02 +0100
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <87czh81tmt.fsf@bsb.me.uk>
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="5f4390e23ad650786eee32d6dd006127";
logging-data="11759"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ngA+pC0sE4g1zvDzX9QjqdcXviOx8o2E="
Cancel-Lock: sha1:0QY3/C29sz5zMhhZiKiW4B5s5FQ=
sha1:tzS403faBOB0w7QKsTkdWPXpYZw=
X-BSB-Auth: 1.6f0ec2297af7cc5c9621.20220423022202BST.87czh81tmt.fsf@bsb.me.uk
 by: Ben - Sat, 23 Apr 2022 01:22 UTC

fir <profesor.fir@gmail.com> writes:

> for(int i=0; i<10; i++)
> {
> int x = 10;
> x++;
> printf("\n %d", x);
> }
>
> for(int i=0; i<10; i++)
> {
> static int x = 10;
> x++;
> printf("\n %d", x);
> }
>
> those two behaves quite differently (though i test in c++ mode must
> say but i assume in standard c it is the same)
>
> are you able to justify/explain the way it behaves is the right way?

A declaration introduces a name. When declared inside a block, that
names is in scope (i.e. can be used) from the declaration to the end of
the block.

A definition, in contrast, creates an object (C's term for some area of
memory that can store values), usually associated with a name because all
definitions are declarations.

Objects have a storage duration. There are four storage durations, but
two matter here: automatic and static. Objects with automatic storage
duration are created when execution reaches the definition and ends when
execution exits the enclosing block. So in your first example, each
time round the loop a new object is created and named x. The
initialisation also happens each time round the loop.

Objects with static storage duration exist from the start of program
execution to the end of program execution and are initialised only once
at program start-up. So in your second look, x names an object that was
created and initialised before the loop was even executed for the first
time.

I make not claims that this justifies anything.

--
Ben.

Re: some observation about declaration in loop

<ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21385&group=comp.lang.c#21385

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:5e42:0:b0:69a:eac:d843 with SMTP id s63-20020a375e42000000b0069a0eacd843mr4368763qkb.526.1650678224019;
Fri, 22 Apr 2022 18:43:44 -0700 (PDT)
X-Received: by 2002:a05:6214:2308:b0:432:e69f:5d71 with SMTP id
gc8-20020a056214230800b00432e69f5d71mr5724753qvb.19.1650678223858; Fri, 22
Apr 2022 18:43:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Apr 2022 18:43:43 -0700 (PDT)
In-Reply-To: <87czh81tmt.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.134; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.134
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com> <87czh81tmt.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
Subject: Re: some observation about declaration in loop
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 23 Apr 2022 01:43:44 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 64
 by: fir - Sat, 23 Apr 2022 01:43 UTC

sobota, 23 kwietnia 2022 o 03:22:18 UTC+2 Ben napisał(a):
> fir <profes...@gmail.com> writes:
>
> > for(int i=0; i<10; i++)
> > {
> > int x = 10;
> > x++;
> > printf("\n %d", x);
> > }
> >
> > for(int i=0; i<10; i++)
> > {
> > static int x = 10;
> > x++;
> > printf("\n %d", x);
> > }
> >
> > those two behaves quite differently (though i test in c++ mode must
> > say but i assume in standard c it is the same)
> >
> > are you able to justify/explain the way it behaves is the right way?
> A declaration introduces a name. When declared inside a block, that
> names is in scope (i.e. can be used) from the declaration to the end of
> the block.
>
> A definition, in contrast, creates an object (C's term for some area of
> memory that can store values), usually associated with a name because all
> definitions are declarations.
>
> Objects have a storage duration. There are four storage durations, but
> two matter here: automatic and static. Objects with automatic storage
> duration are created when execution reaches the definition and ends when
> execution exits the enclosing block. So in your first example, each
> time round the loop a new object is created and named x. The
> initialisation also happens each time round the loop.
>
> Objects with static storage duration exist from the start of program
> execution to the end of program execution and are initialised only once
> at program start-up. So in your second look, x names an object that was
> created and initialised before the loop was even executed for the first
> time.
>
> I make not claims that this justifies anything.
>
ok i should maybe name it definition i guess.. (i name such things often declaration as i understand
it as declare existence of int x here)

well what you say are some 'rules' but the rules are not stated authoritarly but come from some
reasons so i more asked if someone can justify the reasons why is that so ...besides the talk
that {} block in for loop closes and opens each turn of the loop is not convincing imo ..imo its rather more logical to see that this block opens before all turns/loop rotations and then close

hovever i will not state what i think on it personally yet, as im not quite fully sure yet

Re: some observation about declaration in loop

<t3vnpa$9ug$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21386&group=comp.lang.c#21386

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: some observation about declaration in loop
Date: Fri, 22 Apr 2022 19:20:25 -0700
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <t3vnpa$9ug$2@dont-email.me>
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Apr 2022 02:20:27 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e0c88327c6ac61be9834a54ba5572ca4";
logging-data="10192"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cQoJCFc4rkHvg3aNBVYiY"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:7dIkI/YDW5J8cFdO+MCqEDvnM/U=
In-Reply-To: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
Content-Language: en-US
 by: Andrey Tarasevich - Sat, 23 Apr 2022 02:20 UTC

On 4/22/2022 5:42 PM, fir wrote:
> are you able to justify/explain the way it behaves is the right way?

Um... Their behavior is trivially explained by rather boring normal
everyday rules. Nothing remarkable here. Why the the question?

--
Best regards,
Andrey Tarasevich

Re: some observation about declaration in loop

<t3vobk$eu2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21387&group=comp.lang.c#21387

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: some observation about declaration in loop
Date: Fri, 22 Apr 2022 19:30:09 -0700
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <t3vobk$eu2$1@dont-email.me>
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<87czh81tmt.fsf@bsb.me.uk>
<ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Apr 2022 02:30:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e0c88327c6ac61be9834a54ba5572ca4";
logging-data="15298"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182C+KbIZuOaahsKsJGFh2z"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:cu3lHx9PrI3IwWzKPGwYAxBB4Jk=
In-Reply-To: <ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
Content-Language: en-US
 by: Andrey Tarasevich - Sat, 23 Apr 2022 02:30 UTC

On 4/22/2022 6:43 PM, fir wrote:

> ok i should maybe name it definition i guess.. (i name such things often declaration as i understand
> it as declare existence of int x here)

It is normal practice to use the term "declaration" everywhere,
including situations when the declaration in question is actually a
definition.

The only contexts when the term "definition" is used is usually where
you need to emphasize the fact this is a _defining_ declaration - a
definition.

That's the terminological approach used by the Standard, for one example.

> well what you say are some 'rules' but the rules are not stated authoritarly but come from some
> reasons so i more asked if someone can justify the reasons why is that so ..besides the talk
> that {} block in for loop closes and opens each turn of the loop is not convincing imo ..imo its rather more logical to see that this block opens before all turns/loop rotations and then close

Um... The body of the loop has no exclusive loop-specific properties.
When the body of the loop is expressed by a compound statement (a block,
a `{...}`) it has the same properties as compound statement anywhere
else. It begins at `{` and it ends at `}`. All local automatic objects
disappear at `}`. There's no carry-over behavior of any kind granted to
loop bodies just because they are loop bodies. They are regular compound
statements, obeying regular rules. They end after every iteration and
begin anew at the next iteration.

--
Best regards,
Andrey Tarasevich

Re: some observation about declaration in loop

<f6fd53e5-b3bb-438c-8b52-140f09b2eab2n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21388&group=comp.lang.c#21388

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ae9:e71a:0:b0:69e:a5f4:e5f2 with SMTP id m26-20020ae9e71a000000b0069ea5f4e5f2mr4617164qka.662.1650682047667;
Fri, 22 Apr 2022 19:47:27 -0700 (PDT)
X-Received: by 2002:ac8:7f95:0:b0:2f3:479d:1c1d with SMTP id
z21-20020ac87f95000000b002f3479d1c1dmr5451681qtj.345.1650682047541; Fri, 22
Apr 2022 19:47:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Apr 2022 19:47:27 -0700 (PDT)
In-Reply-To: <t3vnpa$9ug$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.224; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.224
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com> <t3vnpa$9ug$2@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f6fd53e5-b3bb-438c-8b52-140f09b2eab2n@googlegroups.com>
Subject: Re: some observation about declaration in loop
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 23 Apr 2022 02:47:27 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 22
 by: fir - Sat, 23 Apr 2022 02:47 UTC

sobota, 23 kwietnia 2022 o 04:20:40 UTC+2 Andrey Tarasevich napisał(a):
> On 4/22/2022 5:42 PM, fir wrote:
> > are you able to justify/explain the way it behaves is the right way?
> Um... Their behavior is trivially explained by rather boring normal
> everyday rules. Nothing remarkable here. Why the the question?
>
what noring normal everyday rules?

question is as i said: for me personally some decisions in language, like how this
above syntax constructs will behave need to be 'justified' by some reason stating
why this is right decision (some may say that i value rationale over the rules
just written - for me it is obvious that rules (language decisions) needs to be justfied/defended that they are right and that other decisions are not more reasonable)

i not thinked yet what i think on thois case but probably those decisions here may be doubtfull for me,
for example i could defend somewhat that imo it should be both 11 12 13 14... or also could defent that both could/shuld be 11 11 11 11..

Re: some observation about declaration in loop

<445bca0b-2009-44f0-9310-a527d679075bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21389&group=comp.lang.c#21389

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:414d:b0:69e:d2a7:c5eb with SMTP id k13-20020a05620a414d00b0069ed2a7c5ebmr4385434qko.771.1650684786545;
Fri, 22 Apr 2022 20:33:06 -0700 (PDT)
X-Received: by 2002:a05:620a:f0d:b0:67e:1c14:bc5e with SMTP id
v13-20020a05620a0f0d00b0067e1c14bc5emr4582156qkl.502.1650684786356; Fri, 22
Apr 2022 20:33:06 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Apr 2022 20:33:06 -0700 (PDT)
In-Reply-To: <f6fd53e5-b3bb-438c-8b52-140f09b2eab2n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.224; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.224
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<t3vnpa$9ug$2@dont-email.me> <f6fd53e5-b3bb-438c-8b52-140f09b2eab2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <445bca0b-2009-44f0-9310-a527d679075bn@googlegroups.com>
Subject: Re: some observation about declaration in loop
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 23 Apr 2022 03:33:06 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 44
 by: fir - Sat, 23 Apr 2022 03:33 UTC

sobota, 23 kwietnia 2022 o 04:47:33 UTC+2 fir napisał(a):
> sobota, 23 kwietnia 2022 o 04:20:40 UTC+2 Andrey Tarasevich napisał(a):
> > On 4/22/2022 5:42 PM, fir wrote:
> > > are you able to justify/explain the way it behaves is the right way?
> > Um... Their behavior is trivially explained by rather boring normal
> > everyday rules. Nothing remarkable here. Why the the question?
> >
> what noring normal everyday rules?
>
> question is as i said: for me personally some decisions in language, like how this
> above syntax constructs will behave need to be 'justified' by some reason stating
> why this is right decision (some may say that i value rationale over the rules
> just written - for me it is obvious that rules (language decisions) needs to be justfied/defended that they are right and that other decisions are not more reasonable)
>
> i not thinked yet what i think on thois case but probably those decisions here may be doubtfull for me,
> for example i could defend somewhat that imo it should be both 11 12 13 14.. or also could defent that both could/shuld be 11 11 11 11..

the arguments i may mention:
1) its weird that adding static drasticaly changes code flow (in fact i was not even clearly aware of that ) i find it rather bad
2) from some point initialisation should initialise only once so in both cases there should be 11 12 13 14..
if no you would need to put initialisation outside loop and its often good to keep declarations close
3) hovever in some cases i could find int x = 10 working this way that it both declares and restets to 10 in each loop also handy (i dont need to write int x; x = 10;)

finally i am not sure, there is also an option
to use syntax like
int x{10} = 2;
where {10} is initialisation and =2 is assigment (it may look idiotic here but this = for initialisation is confusing)
conservatives could say that int x = {10}; could stand for once a loop initialisation and int x = 10,
each turn 'reset'

Re: some observation about declaration in loop

<t3vuer$gd7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21390&group=comp.lang.c#21390

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: some observation about declaration in loop
Date: Fri, 22 Apr 2022 21:14:17 -0700
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <t3vuer$gd7$1@dont-email.me>
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<t3vnpa$9ug$2@dont-email.me>
<f6fd53e5-b3bb-438c-8b52-140f09b2eab2n@googlegroups.com>
<445bca0b-2009-44f0-9310-a527d679075bn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 23 Apr 2022 04:14:19 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e0c88327c6ac61be9834a54ba5572ca4";
logging-data="16807"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fQ+eI5ZyqfW/gZcvEhenF"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:ZrG2N1IqDfAqIHzBN5bXFNEXCyY=
In-Reply-To: <445bca0b-2009-44f0-9310-a527d679075bn@googlegroups.com>
Content-Language: en-US
 by: Andrey Tarasevich - Sat, 23 Apr 2022 04:14 UTC

On 4/22/2022 8:33 PM, fir wrote:
> sobota, 23 kwietnia 2022 o 04:47:33 UTC+2 fir napisał(a):
>> sobota, 23 kwietnia 2022 o 04:20:40 UTC+2 Andrey Tarasevich napisał(a):
>>> On 4/22/2022 5:42 PM, fir wrote:
>>>> are you able to justify/explain the way it behaves is the right way?
>>> Um... Their behavior is trivially explained by rather boring normal
>>> everyday rules. Nothing remarkable here. Why the the question?
>>>
>> what noring normal everyday rules?
>>
>> question is as i said: for me personally some decisions in language, like how this
>> above syntax constructs will behave need to be 'justified' by some reason stating
>> why this is right decision (some may say that i value rationale over the rules
>> just written - for me it is obvious that rules (language decisions) needs to be justfied/defended that they are right and that other decisions are not more reasonable)
>>
>> i not thinked yet what i think on thois case but probably those decisions here may be doubtfull for me,
>> for example i could defend somewhat that imo it should be both 11 12 13 14.. or also could defent that both could/shuld be 11 11 11 11..
>
> the arguments i may mention:
> 1) its weird that adding static drasticaly changes code flow (in fact i was not even clearly aware of that ) i find it rather bad

O_o

Adding `static` is inherently quite drastic. It drastically affects
storage duration and lifetime.

> 2) from some point initialisation should initialise only once so in both cases there should be 11 12 13 14..

It does initialize only once. Once per lifetime.

--
Best regards,
Andrey Tarasevich

Re: some observation about declaration in loop

<d7bec110-a6b1-4514-a7a0-bb1a47c79785@hooterville.invalid>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21391&group=comp.lang.c#21391

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Cancel-Lock: sha1:Bk1oCrxwpt1G8fTdSMuhiksiV+w=
From: arn...@hooterville.invalid (Arnold Ziffel)
Subject: Re: some observation about declaration in loop
Newsgroups: comp.lang.c
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com> <t3vnpa$9ug$2@dont-email.me> <f6fd53e5-b3bb-438c-8b52-140f09b2eab2n@googlegroups.com> <445bca0b-2009-44f0-9310-a527d679075bn@googlegroups.com>
Message-ID: <d7bec110-a6b1-4514-a7a0-bb1a47c79785@hooterville.invalid>
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.10.92-v7+ (armv7l))
Date: 23 Apr 2022 04:52:44 GMT
Lines: 11
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 89.64.86.194
X-Trace: 1650689564 unt-rea-b-01.news.neostrada.pl 470 89.64.86.194:63864
X-Complaints-To: abuse@news.neostrada.pl
X-Received-Bytes: 1498
 by: Arnold Ziffel - Sat, 23 Apr 2022 04:52 UTC

fir <profesor.fir@gmail.com> wrote:

> 1) its weird that adding static drasticaly changes code flow (in fact i was not even clearly aware of that ) i find it rather bad
> 2) from some point initialisation should initialise only once so in both cases there should be 11 12 13 14..

fir, you're writing C for more than I can remember, and you still lack the
understanding of basic language constructs. This is sad.

--
The world is disgracefully managed; one hardly knows to whom to
complain.

Re: some observation about declaration in loop

<e5d26ae3-f4fe-4531-8482-922dd1992eaf@hooterville.invalid>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21392&group=comp.lang.c#21392

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Cancel-Lock: sha1:BdzzBjFfuUVZojr4uAiOvJC/buY=
From: arn...@hooterville.invalid (Arnold Ziffel)
Subject: Re: some observation about declaration in loop
Newsgroups: comp.lang.c
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com> <87czh81tmt.fsf@bsb.me.uk> <ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
Message-ID: <e5d26ae3-f4fe-4531-8482-922dd1992eaf@hooterville.invalid>
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.10.92-v7+ (armv7l))
Date: 23 Apr 2022 04:56:50 GMT
Lines: 19
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 89.64.86.194
X-Trace: 1650689810 unt-rea-b-01.news.neostrada.pl 470 89.64.86.194:63864
X-Complaints-To: abuse@news.neostrada.pl
X-Received-Bytes: 1692
 by: Arnold Ziffel - Sat, 23 Apr 2022 04:56 UTC

fir <profesor.fir@gmail.com> wrote:

> ok i should maybe name it definition i guess.. (i name such things often
> declaration as i understand it as declare existence of int x here)

A declaration might declare the existence, but the existence might be
actually brought to life (defined) elsewhere. That's the difference.

> well what you say are some 'rules' but the rules are not stated
> authoritarly but come from some reasons so i more asked if someone can
> justify the reasons why is that so

Because that's how the static keyword works in this context. It's about
the scope of the variable and whether or not it retains its value.

https://www.geeksforgeeks.org/static-variables-in-c/

--
Never play leapfrog with a unicorn.

Re: some observation about declaration in loop

<t405q3$pn9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21393&group=comp.lang.c#21393

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: the.ha...@gmail.com (Christian Hanné)
Newsgroups: comp.lang.c
Subject: Re: some observation about declaration in loop
Date: Sat, 23 Apr 2022 08:20:05 +0200
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <t405q3$pn9$1@dont-email.me>
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Apr 2022 06:19:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f8878cd36041ec7a8da220aa265ccafb";
logging-data="26345"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QYAuu6lRCV5kbs+78H9nRl90oLLKrpdA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:0nd4gyfOuRtq20gZYpG62LnRhnk=
In-Reply-To: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
Content-Language: de-DE
 by: Christian Hanné - Sat, 23 Apr 2022 06:20 UTC

Am 23.04.2022 um 02:42 schrieb fir:
> may seem funny but i tend to always not remember how declaration of in in loop behaves (though im not c newb for sure)
>
> for(int i=0; i<10; i++)
> {
> int x = 10;
> x++;
> printf("\n %d", x);
> }
>
> for(int i=0; i<10; i++)
> {
> static int x = 10;
> x++;
> printf("\n %d", x);
> }

The only problem with the latter code is that it isn't thread-safe.
Better use thread_local. Aside from that both codes are identical.

Re: some observation about declaration in loop

<d5154601-fa1f-428e-b327-c4369a0529cdn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21397&group=comp.lang.c#21397

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:4104:b0:42c:1db0:da28 with SMTP id kc4-20020a056214410400b0042c1db0da28mr6414041qvb.67.1650710221968;
Sat, 23 Apr 2022 03:37:01 -0700 (PDT)
X-Received: by 2002:a05:6214:212c:b0:443:cacc:ee8 with SMTP id
r12-20020a056214212c00b00443cacc0ee8mr6427030qvc.96.1650710221875; Sat, 23
Apr 2022 03:37:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 23 Apr 2022 03:37:01 -0700 (PDT)
In-Reply-To: <d7bec110-a6b1-4514-a7a0-bb1a47c79785@hooterville.invalid>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.243; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.243
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<t3vnpa$9ug$2@dont-email.me> <f6fd53e5-b3bb-438c-8b52-140f09b2eab2n@googlegroups.com>
<445bca0b-2009-44f0-9310-a527d679075bn@googlegroups.com> <d7bec110-a6b1-4514-a7a0-bb1a47c79785@hooterville.invalid>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d5154601-fa1f-428e-b327-c4369a0529cdn@googlegroups.com>
Subject: Re: some observation about declaration in loop
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 23 Apr 2022 10:37:01 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 12
 by: fir - Sat, 23 Apr 2022 10:37 UTC

sobota, 23 kwietnia 2022 o 06:52:56 UTC+2 Arnold Ziffel napisał(a):
> fir <profes...@gmail.com> wrote:
>
> > 1) its weird that adding static drasticaly changes code flow (in fact i was not even clearly aware of that ) i find it rather bad
> > 2) from some point initialisation should initialise only once so in both cases there should be 11 12 13 14..
> fir, you're writing C for more than I can remember, and you still lack the
> understanding of basic language constructs. This is sad.
>
maybe for you..for me its rather funny

Re: some observation about declaration in loop

<81522462-9d10-438f-84ef-79228425f089n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21399&group=comp.lang.c#21399

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ae9:e71a:0:b0:69e:a5f4:e5f2 with SMTP id m26-20020ae9e71a000000b0069ea5f4e5f2mr5223389qka.662.1650710816499;
Sat, 23 Apr 2022 03:46:56 -0700 (PDT)
X-Received: by 2002:a05:6214:27c9:b0:446:5771:397b with SMTP id
ge9-20020a05621427c900b004465771397bmr6559092qvb.75.1650710816349; Sat, 23
Apr 2022 03:46:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 23 Apr 2022 03:46:56 -0700 (PDT)
In-Reply-To: <d5154601-fa1f-428e-b327-c4369a0529cdn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.243; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.243
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<t3vnpa$9ug$2@dont-email.me> <f6fd53e5-b3bb-438c-8b52-140f09b2eab2n@googlegroups.com>
<445bca0b-2009-44f0-9310-a527d679075bn@googlegroups.com> <d7bec110-a6b1-4514-a7a0-bb1a47c79785@hooterville.invalid>
<d5154601-fa1f-428e-b327-c4369a0529cdn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <81522462-9d10-438f-84ef-79228425f089n@googlegroups.com>
Subject: Re: some observation about declaration in loop
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 23 Apr 2022 10:46:56 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 16
 by: fir - Sat, 23 Apr 2022 10:46 UTC

sobota, 23 kwietnia 2022 o 12:37:08 UTC+2 fir napisał(a):
> sobota, 23 kwietnia 2022 o 06:52:56 UTC+2 Arnold Ziffel napisał(a):
> > fir <profes...@gmail.com> wrote:
> >
> > > 1) its weird that adding static drasticaly changes code flow (in fact i was not even clearly aware of that ) i find it rather bad
> > > 2) from some point initialisation should initialise only once so in both cases there should be 11 12 13 14..
> > fir, you're writing C for more than I can remember, and you still lack the
> > understanding of basic language constructs. This is sad.
> >
> maybe for you..for me its rather funny
i wouldnt say its a lack of understanding though, its rather a lack of remembering, some things i rarely use i may check before using but i am able to forget it again

Re: some observation about declaration in loop

<f13ac0fb-fd64-4902-8ce3-a529568e12c2n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21400&group=comp.lang.c#21400

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:2416:b0:69f:534:4a37 with SMTP id d22-20020a05620a241600b0069f05344a37mr5046648qkn.527.1650711480635;
Sat, 23 Apr 2022 03:58:00 -0700 (PDT)
X-Received: by 2002:a05:622a:1356:b0:2f1:f997:7857 with SMTP id
w22-20020a05622a135600b002f1f9977857mr6286580qtk.50.1650711480491; Sat, 23
Apr 2022 03:58:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 23 Apr 2022 03:58:00 -0700 (PDT)
In-Reply-To: <t405q3$pn9$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.243; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.243
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com> <t405q3$pn9$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f13ac0fb-fd64-4902-8ce3-a529568e12c2n@googlegroups.com>
Subject: Re: some observation about declaration in loop
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 23 Apr 2022 10:58:00 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 26
 by: fir - Sat, 23 Apr 2022 10:58 UTC

sobota, 23 kwietnia 2022 o 08:20:01 UTC+2 Christian Hanné napisał(a):
> Am 23.04.2022 um 02:42 schrieb fir:
> > may seem funny but i tend to always not remember how declaration of in in loop behaves (though im not c newb for sure)
> >
> > for(int i=0; i<10; i++)
> > {
> > int x = 10;
> > x++;
> > printf("\n %d", x);
> > }
> >
> > for(int i=0; i<10; i++)
> > {
> > static int x = 10;
> > x++;
> > printf("\n %d", x);
> > }
> The only problem with the latter code is that it isn't thread-safe.
> Better use thread_local. Aside from that both codes are identical.

im not writing multi-threaded code, i think such kind of coding is not-elegant

if some want paralelistation it would be better to paralellize
critical loops (so called kernels)

Re: some observation about declaration in loop

<877d7g10vh.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21403&group=comp.lang.c#21403

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.lang.c
Subject: Re: some observation about declaration in loop
Date: Sat, 23 Apr 2022 12:43:14 +0100
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <877d7g10vh.fsf@bsb.me.uk>
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<87czh81tmt.fsf@bsb.me.uk>
<ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
<e5d26ae3-f4fe-4531-8482-922dd1992eaf@hooterville.invalid>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="5f4390e23ad650786eee32d6dd006127";
logging-data="26516"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Dp37CBqVmjDkT3oxkrnLCPH3hHH5VJw4="
Cancel-Lock: sha1:I71ZR+GC0MeerCRta9QfKgttXes=
sha1:fy51Ef7KzfndOJbGAZd+y9kZRqI=
X-BSB-Auth: 1.339e051fc2999f68cb03.20220423124314BST.877d7g10vh.fsf@bsb.me.uk
 by: Ben - Sat, 23 Apr 2022 11:43 UTC

arnold@hooterville.invalid (Arnold Ziffel) writes:

> fir <profesor.fir@gmail.com> wrote:

>> well what you say are some 'rules' but the rules are not stated
>> authoritarly but come from some reasons so i more asked if someone can
>> justify the reasons why is that so
>
> Because that's how the static keyword works in this context. It's about
> the scope of the variable and whether or not it retains its value.

static affects lifetime, not scope. Lifetime is a dynamic property of
objects, scope is a static property of names.

> https://www.geeksforgeeks.org/static-variables-in-c/

Who writes these things?

--
Ben.

Re: some observation about declaration in loop

<871qxo10lc.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21405&group=comp.lang.c#21405

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.lang.c
Subject: Re: some observation about declaration in loop
Date: Sat, 23 Apr 2022 12:49:19 +0100
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <871qxo10lc.fsf@bsb.me.uk>
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<87czh81tmt.fsf@bsb.me.uk>
<ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="5f4390e23ad650786eee32d6dd006127";
logging-data="26516"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18eoOqNFtMyquTwAbp99BIInnPkcs6l7IY="
Cancel-Lock: sha1:unFg0pFAt9YpNe1kn9GzKhzvmxg=
sha1:4R7iIr/t+3gE5jN8UiDIZbeDtwA=
X-BSB-Auth: 1.24f5d00713a24e3dfdd6.20220423124919BST.871qxo10lc.fsf@bsb.me.uk
 by: Ben - Sat, 23 Apr 2022 11:49 UTC

fir <profesor.fir@gmail.com> writes:

> well what you say are some 'rules' but the rules are not stated
> authoritarly but come from some reasons so i more asked if someone can
> justify the reasons why is that so

Yes, I knew that's what you were asking but I've been on Usenet long
enough to know that there would be no point in my addressing it.
Instead, your question seemed to be a good place to comment on the all
too common confusion between scope and lifetime.

--
Ben.

Re: some observation about declaration in loop

<332337a6-63db-4ee9-b6a4-47f08f5484ebn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21406&group=comp.lang.c#21406

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:5a89:0:b0:2f3:5ab1:3e4f with SMTP id c9-20020ac85a89000000b002f35ab13e4fmr4566420qtc.528.1650715944390;
Sat, 23 Apr 2022 05:12:24 -0700 (PDT)
X-Received: by 2002:a37:a8c3:0:b0:69e:5f25:3e60 with SMTP id
r186-20020a37a8c3000000b0069e5f253e60mr5432786qke.58.1650715944177; Sat, 23
Apr 2022 05:12:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 23 Apr 2022 05:12:23 -0700 (PDT)
In-Reply-To: <877d7g10vh.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.157; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.157
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<87czh81tmt.fsf@bsb.me.uk> <ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
<e5d26ae3-f4fe-4531-8482-922dd1992eaf@hooterville.invalid> <877d7g10vh.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <332337a6-63db-4ee9-b6a4-47f08f5484ebn@googlegroups.com>
Subject: Re: some observation about declaration in loop
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 23 Apr 2022 12:12:24 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 63
 by: fir - Sat, 23 Apr 2022 12:12 UTC

sobota, 23 kwietnia 2022 o 13:43:26 UTC+2 Ben napisał(a):
> arn...@hooterville.invalid (Arnold Ziffel) writes:
> > fir <profes...@gmail.com> wrote:
>
> >> well what you say are some 'rules' but the rules are not stated
> >> authoritarly but come from some reasons so i more asked if someone can
> >> justify the reasons why is that so
> >
> > Because that's how the static keyword works in this context. It's about
> > the scope of the variable and whether or not it retains its value.
> static affects lifetime, not scope. Lifetime is a dynamic property of
> objects, scope is a static property of names.
>

here for me, its not a matter of 'storage' (lifetime) this is if it is static
imo this is more about expression becouse int a = 1; (or static int a = 1;)
is expression, and some constricts in c are meant to be usefull and it is more
better to be more usefull than less

in fact the main usabiulity of this above expression is in facty that it initialises
variable - and in fact if see this way int x = 1; initialises int static int x = 1; also initialises
hovever if so the behaviour of "int x = 10" when it restets each time to 10 its probably
wrong (seeint it this way)

it hovever as i already said it has this side effect that sometiumes you just write
int x = 10; instead of int x = 10; x = 10; when you want this.. at the moment i could say
that in a context of c in my opinion it could be

for(int i=0;i<10;i++) {
int x = {10}; printf("\n %d",x); // 10 11 12 13....
int y =10; printf("\n %d",y); // 10 10 10 10....
static int z = {10}; printf("\n %d", z); // 10 11 12 13....
static int w= 10; printf("\n %d",w); // 10 10 10 10....
x++; y++; z++;w++;
}

for me it would be more logical, but this is only my opinion..
and if someone wouldnt wont to add this = {} syntax and stay only with

int x = 10;
static int x = 10;
then in that case it boiuth imp probably would better give 10 11 12 13...

> > https://www.geeksforgeeks.org/static-variables-in-c/
>
> Who writes these things?
>

Re: some observation about declaration in loop

<d6636047-165f-468c-b031-d1b1815d464dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21407&group=comp.lang.c#21407

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:13c8:b0:2f3:5421:d64d with SMTP id p8-20020a05622a13c800b002f35421d64dmr6342949qtk.43.1650716085827;
Sat, 23 Apr 2022 05:14:45 -0700 (PDT)
X-Received: by 2002:ae9:c30d:0:b0:69e:bd20:40cc with SMTP id
n13-20020ae9c30d000000b0069ebd2040ccmr5449986qkg.10.1650716085614; Sat, 23
Apr 2022 05:14:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 23 Apr 2022 05:14:45 -0700 (PDT)
In-Reply-To: <871qxo10lc.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.157; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.157
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<87czh81tmt.fsf@bsb.me.uk> <ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
<871qxo10lc.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d6636047-165f-468c-b031-d1b1815d464dn@googlegroups.com>
Subject: Re: some observation about declaration in loop
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 23 Apr 2022 12:14:45 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 14
 by: fir - Sat, 23 Apr 2022 12:14 UTC

sobota, 23 kwietnia 2022 o 13:49:32 UTC+2 Ben napisał(a):
> fir <profes...@gmail.com> writes:
>
> > well what you say are some 'rules' but the rules are not stated
> > authoritarly but come from some reasons so i more asked if someone can
> > justify the reasons why is that so
> Yes, I knew that's what you were asking but I've been on Usenet long
> enough to know that there would be no point in my addressing it.
> Instead, your question seemed to be a good place to comment on the all
> too common confusion between scope and lifetime.
>
sure, anybody says what he wants...
i only state a question to gave oportunity for people
who wants to say on this to say what they want ,

Re: some observation about declaration in loop

<t414fc$35otq$1@paganini.bofh.team>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21415&group=comp.lang.c#21415

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!not-for-mail
From: inva...@invalid.net (Jack Lemmon)
Newsgroups: comp.lang.c
Subject: Re: some observation about declaration in loop
Date: Sat, 23 Apr 2022 15:00:32 +0100
Organization: To protect and to server
Message-ID: <t414fc$35otq$1@paganini.bofh.team>
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<t3vnpa$9ug$2@dont-email.me>
<f6fd53e5-b3bb-438c-8b52-140f09b2eab2n@googlegroups.com>
<445bca0b-2009-44f0-9310-a527d679075bn@googlegroups.com>
<d7bec110-a6b1-4514-a7a0-bb1a47c79785@hooterville.invalid>
Mime-Version: 1.0
Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Apr 2022 15:03:08 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="3335098"; posting-host="xWoSobfAAAMkUmDG6ndrsw.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
X-Notice: Filtered by postfilter v. 0.9.1
Content-Language: en-US
 by: Jack Lemmon - Sat, 23 Apr 2022 14:00 UTC

On 23/04/2022 05:52, Arnold Ziffel wrote:
> fir, you're writing C for more than I can remember, and you still lack the
> understanding of basic language constructs. This is sad.
>
When people say they have been programming for xx number of years then
you know that they have passed their best!

A young person is likely to try something new all the time and he is
also likely to be thinking about the problem and possible improvements
all the time while an experienced person will simply say "I know it, I
have been programming for 30 years! Don't tell me how to do it".

Tech companies will hire a younger person more than someone who has been
programming for 30 years. It has nothing to do with pay structure; It is
to do with attitude of the so called experienced person.

Re: some observation about declaration in loop

<BFW8K.630276$LN2.557300@fx13.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21417&group=comp.lang.c#21417

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx13.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.8.1
Subject: Re: some observation about declaration in loop
Content-Language: en-US
Newsgroups: comp.lang.c
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<87czh81tmt.fsf@bsb.me.uk>
<ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
<e5d26ae3-f4fe-4531-8482-922dd1992eaf@hooterville.invalid>
<877d7g10vh.fsf@bsb.me.uk>
<332337a6-63db-4ee9-b6a4-47f08f5484ebn@googlegroups.com>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <332337a6-63db-4ee9-b6a4-47f08f5484ebn@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 85
Message-ID: <BFW8K.630276$LN2.557300@fx13.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sat, 23 Apr 2022 13:26:56 -0400
X-Received-Bytes: 4354
 by: Richard Damon - Sat, 23 Apr 2022 17:26 UTC

On 4/23/22 8:12 AM, fir wrote:
> sobota, 23 kwietnia 2022 o 13:43:26 UTC+2 Ben napisał(a):
>> arn...@hooterville.invalid (Arnold Ziffel) writes:
>>> fir <profes...@gmail.com> wrote:
>>
>>>> well what you say are some 'rules' but the rules are not stated
>>>> authoritarly but come from some reasons so i more asked if someone can
>>>> justify the reasons why is that so
>>>
>>> Because that's how the static keyword works in this context. It's about
>>> the scope of the variable and whether or not it retains its value.
>> static affects lifetime, not scope. Lifetime is a dynamic property of
>> objects, scope is a static property of names.
>>
>
> here for me, its not a matter of 'storage' (lifetime) this is if it is static
> imo this is more about expression becouse int a = 1; (or static int a = 1;)
> is expression, and some constricts in c are meant to be usefull and it is more
> better to be more usefull than less
>
> in fact the main usabiulity of this above expression is in facty that it initialises
> variable - and in fact if see this way int x = 1; initialises int static int x = 1; also initialises
> hovever if so the behaviour of "int x = 10" when it restets each time to 10 its probably
> wrong (seeint it this way)
>
> it hovever as i already said it has this side effect that sometiumes you just write
> int x = 10; instead of int x = 10; x = 10; when you want this.. at the moment i could say
> that in a context of c in my opinion it could be
>
> for(int i=0;i<10;i++) {
> int x = {10}; printf("\n %d",x); // 10 11 12 13....
> int y =10; printf("\n %d",y); // 10 10 10 10....
> static int z = {10}; printf("\n %d", z); // 10 11 12 13....
> static int w= 10; printf("\n %d",w); // 10 10 10 10....
> x++; y++; z++;w++;
> }
>
> for me it would be more logical, but this is only my opinion..
> and if someone wouldnt wont to add this = {} syntax and stay only with
>
> int x = 10;
> static int x = 10;
> then in that case it boiuth imp probably would better give 10 11 12 13...
>
>

The key difference between

int x = 10;

and

int x;
x = 10;

is that the first INITIALIZES x when it is created, and the second
ASSIGNS it when the statement is executed.

When we change that to

static int x = 10;

Then by the rules of the C language, that initialization will only
happen the first time that we reach that statement, as after that the
variable has already been created, so it isn't initiialized again.

In fact, behind the scenes, there needs to be some other hidden flag
created by the implementation to know if initialization has happened.

Another way to look at it, if we look at C++ (which makes things more
explicit here) and use a user defined type:

Foo x = 10;

will use the constructor Foo(int) to create the variable, while:

Foo x;
x = 10;

Will first use the default constructor Foo() to create the variable, and
then Foo::operator =(int) to assign the value to the created variable.

(and if that isn't available use Foo(int) to make a temporary, and then
Foo::operator=(Foo&&) to assign the value).

Re: some observation about declaration in loop

<97afe458-a302-4cd0-89dc-e6416daf2948n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21418&group=comp.lang.c#21418

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a0c:d7cb:0:b0:444:2b27:80d3 with SMTP id g11-20020a0cd7cb000000b004442b2780d3mr7735691qvj.57.1650736209019;
Sat, 23 Apr 2022 10:50:09 -0700 (PDT)
X-Received: by 2002:a05:6214:4108:b0:456:31ce:d5ff with SMTP id
kc8-20020a056214410800b0045631ced5ffmr725913qvb.127.1650736208900; Sat, 23
Apr 2022 10:50:08 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 23 Apr 2022 10:50:08 -0700 (PDT)
In-Reply-To: <ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=87.112.250.40; posting-account=3b1IMQoAAABTaHj6KDu9rDX4VoUvTgIu
NNTP-Posting-Host: 87.112.250.40
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<87czh81tmt.fsf@bsb.me.uk> <ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <97afe458-a302-4cd0-89dc-e6416daf2948n@googlegroups.com>
Subject: Re: some observation about declaration in loop
From: lorif32...@gmail.com (Lori Fairhead)
Injection-Date: Sat, 23 Apr 2022 17:50:09 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 92
 by: Lori Fairhead - Sat, 23 Apr 2022 17:50 UTC

On Saturday, April 23, 2022 at 2:43:51 AM UTC+1, fir wrote:
> sobota, 23 kwietnia 2022 o 03:22:18 UTC+2 Ben napisał(a):
> > fir <profes...@gmail.com> writes:
> >
> > > for(int i=0; i<10; i++)
> > > {
> > > int x = 10;
> > > x++;
> > > printf("\n %d", x);
> > > }
> > >
> > > for(int i=0; i<10; i++)
> > > {
> > > static int x = 10;
> > > x++;
> > > printf("\n %d", x);
> > > }
> > >
> > > those two behaves quite differently (though i test in c++ mode must
> > > say but i assume in standard c it is the same)
> > >
> > > are you able to justify/explain the way it behaves is the right way?
> > A declaration introduces a name. When declared inside a block, that
> > names is in scope (i.e. can be used) from the declaration to the end of
> > the block.
> >
> > A definition, in contrast, creates an object (C's term for some area of
> > memory that can store values), usually associated with a name because all
> > definitions are declarations.
> >
> > Objects have a storage duration. There are four storage durations, but
> > two matter here: automatic and static. Objects with automatic storage
> > duration are created when execution reaches the definition and ends when
> > execution exits the enclosing block. So in your first example, each
> > time round the loop a new object is created and named x. The
> > initialisation also happens each time round the loop.
> >
> > Objects with static storage duration exist from the start of program
> > execution to the end of program execution and are initialised only once
> > at program start-up. So in your second look, x names an object that was
> > created and initialised before the loop was even executed for the first
> > time.
> >
> > I make not claims that this justifies anything.
> >
> ok i should maybe name it definition i guess.. (i name such things often declaration as i understand
> it as declare existence of int x here)
>
> well what you say are some 'rules' but the rules are not stated authoritarly but come from some
> reasons so i more asked if someone can justify the reasons why is that so ..besides the talk
> that {} block in for loop closes and opens each turn of the loop is not convincing imo ..imo its rather more logical to see that this block opens before all turns/loop rotations and then close
>

Just think of it as FOR parameters DO command

Each time the paramters tell FOR to execute the command

In this case the command is a BLOCK so the block is executed
again and again for each iteration of the FOR loop.

You can have a BLOCK anywhere you have a command like several other
languages.

Also this is useful for extra temporary variables
if you wanted to partition them

int a,b;
puts("hello there");
a=14; b=17;
{int t; t=a; a=b; b=t; }

Also you can do many useful things using static variables
in a block

REGARDS LF
> hovever i will not state what i think on it personally yet, as im not quite fully sure yet

Re: some observation about declaration in loop

<sml86h115ablteo7kjlil7dkedhr853s2n@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21419&group=comp.lang.c#21419

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: schwa...@delq.com (Barry Schwarz)
Newsgroups: comp.lang.c
Subject: Re: some observation about declaration in loop
Date: Sat, 23 Apr 2022 12:49:37 -0700
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <sml86h115ablteo7kjlil7dkedhr853s2n@4ax.com>
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com> <87czh81tmt.fsf@bsb.me.uk> <ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com> <e5d26ae3-f4fe-4531-8482-922dd1992eaf@hooterville.invalid> <877d7g10vh.fsf@bsb.me.uk> <332337a6-63db-4ee9-b6a4-47f08f5484ebn@googlegroups.com> <BFW8K.630276$LN2.557300@fx13.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="e76668b080264c1b9556a3eb25371147";
logging-data="3153"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pOJwWR1OYzNfOMl/Jz/cvjhvTd59P69I="
Cancel-Lock: sha1:tviPm1HmkC9r8wTV9MZWwe3U3P8=
X-Newsreader: Forte Agent 4.2/32.1118
 by: Barry Schwarz - Sat, 23 Apr 2022 19:49 UTC

On Sat, 23 Apr 2022 13:26:56 -0400, Richard Damon
<Richard@Damon-Family.org> wrote:

>The key difference between
>
>int x = 10;
>
>and
>
>int x;
>x = 10;
>
>is that the first INITIALIZES x when it is created, and the second
>ASSIGNS it when the statement is executed.
>
>When we change that to
>
>static int x = 10;
>
>Then by the rules of the C language, that initialization will only
>happen the first time that we reach that statement, as after that the
>variable has already been created, so it isn't initiialized again.
>
>In fact, behind the scenes, there needs to be some other hidden flag
>created by the implementation to know if initialization has happened.

I disagree. Paragraph 5.1.2 of C11 explicitly states that a static
variable is initialized prior to program start up.

The key difference between "int x" (or "int x=10") and "static int x"
(with or without explicit initialization) is that during execution the
former causes the variable to be created (and initialized if
specified) while the latter does absolutely nothing since the variable
has already been created and initialized.

A hidden flag is not needed at all.

--
Remove del for email

Re: some observation about declaration in loop

<7638ae7e-9cf4-4590-9ee4-89ffe02a3741@hooterville.invalid>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21420&group=comp.lang.c#21420

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Cancel-Lock: sha1:XslVfOWR08TM/4Cbgvj3DB7j7FY=
From: arn...@hooterville.invalid (Arnold Ziffel)
Subject: Re: some observation about declaration in loop
Newsgroups: comp.lang.c
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com> <t3vnpa$9ug$2@dont-email.me> <f6fd53e5-b3bb-438c-8b52-140f09b2eab2n@googlegroups.com> <445bca0b-2009-44f0-9310-a527d679075bn@googlegroups.com> <d7bec110-a6b1-4514-a7a0-bb1a47c79785@hooterville.invalid> <d5154601-fa1f-428e-b327-c4369a0529cdn@googlegroups.com> <81522462-9d10-438f-84ef-79228425f089n@googlegroups.com>
Message-ID: <7638ae7e-9cf4-4590-9ee4-89ffe02a3741@hooterville.invalid>
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.10.92-v7+ (armv7l))
Date: 23 Apr 2022 20:08:24 GMT
Lines: 11
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 89.64.86.194
X-Trace: 1650744504 unt-rea-a-02.news.neostrada.pl 470 89.64.86.194:64000
X-Complaints-To: abuse@news.neostrada.pl
X-Received-Bytes: 1562
 by: Arnold Ziffel - Sat, 23 Apr 2022 20:08 UTC

fir <profesor.fir@gmail.com> wrote:

> i wouldnt say its a lack of understanding though, its rather a lack of
> remembering, some things i rarely use i may check before using but i am
> able to forget it again

You have to get more sleep to improve your memory...

--
An expert is one who knows more and more about less and less until he
knows absolutely everything about nothing.

Re: some observation about declaration in loop

<t41mhb$17dlk$1@news.mixmin.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21421&group=comp.lang.c#21421

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.mixmin.net!.POSTED!not-for-mail
From: samlara...@gmail.com (Sams Lara)
Newsgroups: comp.lang.c
Subject: Re: some observation about declaration in loop
Date: Sat, 23 Apr 2022 21:08:44 +0100
Organization: Microsoft Unofficial Representative on Newsgroups
Message-ID: <t41mhb$17dlk$1@news.mixmin.net>
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
<87czh81tmt.fsf@bsb.me.uk>
<ac67c805-e5cf-489b-ab72-9effbee3e1ccn@googlegroups.com>
<e5d26ae3-f4fe-4531-8482-922dd1992eaf@hooterville.invalid>
<877d7g10vh.fsf@bsb.me.uk>
<332337a6-63db-4ee9-b6a4-47f08f5484ebn@googlegroups.com>
<BFW8K.630276$LN2.557300@fx13.iad>
<sml86h115ablteo7kjlil7dkedhr853s2n@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Apr 2022 20:11:23 -0000 (UTC)
Injection-Info: news.mixmin.net; posting-host="48d11a3b2fa45924111005cb39b9d63a5dfc88a3";
logging-data="1291956"; mail-complaints-to="abuse@mixmin.net"
In-Reply-To: <sml86h115ablteo7kjlil7dkedhr853s2n@4ax.com>
Content-Language: en-us
 by: Sams Lara - Sat, 23 Apr 2022 20:08 UTC

On 23/04/2022 20:49, Barry Schwarz wrote:
> while the latter does absolutely nothing since the variable
> has already been created and initialized.
>
>
In other words no memory is allocated at this stage.

Re: some observation about declaration in loop

<2a60031d-9645-4f13-b105-544eaeefca8bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21422&group=comp.lang.c#21422

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:29e6:b0:44a:2d0f:bf63 with SMTP id jv6-20020a05621429e600b0044a2d0fbf63mr8399603qvb.93.1650752852724;
Sat, 23 Apr 2022 15:27:32 -0700 (PDT)
X-Received: by 2002:a05:620a:13a3:b0:69e:13f4:6f96 with SMTP id
m3-20020a05620a13a300b0069e13f46f96mr6456493qki.100.1650752852593; Sat, 23
Apr 2022 15:27:32 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 23 Apr 2022 15:27:32 -0700 (PDT)
In-Reply-To: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=80.192.51.129; posting-account=rqC7UgoAAACeVvrGykivrxfPIl3bA_1y
NNTP-Posting-Host: 80.192.51.129
References: <194cbd97-9fad-4958-927c-b48c2cfe2df5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2a60031d-9645-4f13-b105-544eaeefca8bn@googlegroups.com>
Subject: Re: some observation about declaration in loop
From: bart4...@gmail.com (bart c)
Injection-Date: Sat, 23 Apr 2022 22:27:32 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 28
 by: bart c - Sat, 23 Apr 2022 22:27 UTC

On Saturday, 23 April 2022 at 01:43:00 UTC+1, fir wrote:
> may seem funny but i tend to always not remember how declaration of in in loop behaves (though im not c newb for sure)
>
> for(int i=0; i<10; i++)
> {
> int x = 10;
> x++;
> printf("\n %d", x);
> }
>
> for(int i=0; i<10; i++)
> {
> static int x = 10;
> x++;
> printf("\n %d", x);
> }
>
> those two behaves quite differently (though i test in c++ mode must say but i assume in standard c it is the same)
>
> are you able to justify/explain the way it behaves is the right way?

Inside a function:

int x = 10; // initialised to 10 each time it is encountered (eg. per loop)

static int x = 10; // initialised to 10 at load-time (actually, set in .data section of exe)

If this was written with my syntax, it would clearer as the first is written using `x := 10`, and the second using `x = 10`. `:=` means a runtime assignment. `=` is taken care at compile-time/load-time.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor