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


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

kandr2 question

Started by"Bill Cunningham" <nospam@nspam.invalid>
First post2012-10-30 17:41 -0500
Last post2012-10-31 20:04 -0500
Articles 20 on this page of 85 — 18 participants

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


Contents

  kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 17:41 -0500
    Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 14:48 -0700
      Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 17:50 -0500
        Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 14:56 -0700
          Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 15:01 -0700
            Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:07 -0700
              Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:12 -0500
                Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:15 -0700
                  Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:25 -0500
                    Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:27 -0700
                      Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:59 -0500
                    Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:29 -0800
              Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 15:30 -0700
                Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:36 -0700
              Re: kandr2 question Kenneth Brody <kenbrody@spamcop.net> - 2012-10-31 14:15 -0400
          Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:04 -0500
            Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:07 -0700
              Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:09 -0500
                Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:13 -0700
                  Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:30 -0500
                    Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:50 -0700
                      Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 19:28 -0500
                        Re: kandr2 question Lew Pitcher <lpitcher@teksavvy.com> - 2012-10-30 19:39 -0400
                          Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 19:50 -0500
                            Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:45 -0800
                        Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:43 -0800
                    Re: kandr2 question Kenneth Brody <kenbrody@spamcop.net> - 2012-10-31 14:21 -0400
                    Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:43 -0800
                Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:40 -0800
            Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 15:31 -0700
              Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:36 -0700
            Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:37 -0800
          Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:07 -0500
            Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:10 -0700
              Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:47 -0500
                Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:52 -0700
          Re: kandr2 question "BartC" <bc@freeuk.com> - 2012-10-30 22:08 +0000
            Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:11 -0700
              Re: kandr2 question James Kuyper <jameskuyper@verizon.net> - 2012-10-30 18:36 -0400
                Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:44 -0500
                  Re: kandr2 question tom st denis <tom@iahu.ca> - 2012-10-30 15:53 -0700
                    Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 19:06 -0500
                    Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 19:12 -0500
              Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:49 -0800
          Re: kandr2 question Old Wolf <oldwolf@inspire.net.nz> - 2012-11-11 14:37 -0800
        Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:27 -0800
    Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 15:00 -0700
      Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 18:18 -0500
    Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 16:13 -0700
      Re: kandr2 question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-30 23:31 +0000
        Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 17:45 -0700
        Re: kandr2 question Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2012-10-31 05:43 -0700
          Re: kandr2 question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-31 13:33 +0000
            Re: kandr2 question James Kuyper <jameskuyper@verizon.net> - 2012-10-31 10:27 -0400
              Re: kandr2 question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-31 16:11 +0000
                Re: kandr2 question Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2012-11-07 14:53 -0800
          Re: kandr2 question James Kuyper <jameskuyper@verizon.net> - 2012-10-31 10:38 -0400
      Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-30 19:39 -0500
        Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-30 17:51 -0700
          Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 13:47 -0500
            Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:55 -0800
          Re: kandr2 question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-31 19:48 +0200
          Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 06:52 -0800
            Re: kandr2 question hormelfree@gmail.com - 2012-11-10 11:23 -0800
      Re: kandr2 question "BartC" <bc@freeuk.com> - 2012-10-31 01:56 +0000
    Re: kandr2 question "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-10-30 18:44 -0700
    Re: kandr2 question Barry Schwarz <schwarz45@yahoo.com> - 2012-10-30 20:32 -0700
      Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 13:52 -0500
        Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-31 11:20 -0700
          Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 14:37 -0500
            Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 14:40 -0500
            Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-31 12:18 -0700
              Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 15:29 -0500
              Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 16:56 -0500
                Re: kandr2 question Keith Thompson <kst-u@mib.org> - 2012-10-31 15:05 -0700
                  Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-01 13:11 -0500
        Re: kandr2 question Barry Schwarz <schwarz45@yahoo.com> - 2012-10-31 21:44 -0700
          Re: kandr2 question Ike Naar <ike@sverige.freeshell.org> - 2012-11-01 09:34 +0000
            Re: kandr2 question Barry Schwarz <schwarzb@dqel.com> - 2012-11-01 12:13 -0700
              Re: kandr2 question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-10 07:04 -0800
            Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-01 15:26 -0500
          Re: kandr2 question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-11-01 17:56 +0200
          Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-01 13:14 -0500
    Re: kandr2 question SG <sgesemann@gmail.invalid> - 2012-10-31 20:14 +0100
      Re: kandr2 question "Bill Cunningham" <nospam@nspam.invalid> - 2012-10-31 20:04 -0500

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


#27882

Fromtom st denis <tom@iahu.ca>
Date2012-10-30 15:53 -0700
Message-ID<46602fc4-cd46-4cbb-a2c5-80cccbae4896@o8g2000yqh.googlegroups.com>
In reply to#27877
On Oct 30, 6:44 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
> James Kuyper wrote:
> > It is, of course, completely unreasonable for someone like Bill
> > Cunningham, who has been "learning" C for more than a decade, and
> > should therefore have long since ceased being a newbie, to be unaware
> > of this fact.
>
>     No I'm not a newbie. And I know they mean the same here in this
> circustance. I was wondering why they weren't using the char *s convention.
> I will have to answer my own question and guess they are trying to simplify
> things. If that guy thinks I'm trolling why is he talking to me and to come
> right say I don't understand the likenesses in char *s and char s[] is an
> insult to me.

Who the fuck knows why they used it.  I replied the way I did to your
post because you're an annoying person who asks retarded questions
over and over because you like to post nonsense.  You're not "learning
C."   It doesn't take 10+ years to learn C to a degree where you can
successfully write things like "I want to write an integer to a file"
or whatever your random project of the week is.

Tom

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


#27885

From"Bill Cunningham" <nospam@nspam.invalid>
Date2012-10-30 19:06 -0500
Message-ID<k6pmgr$jj2$1@dont-email.me>
In reply to#27882
tom st denis wrote:

> Who the fuck knows why they used it.  I replied the way I did to your
> post because you're an annoying person who asks retarded questions
> over and over because you like to post nonsense.  You're not "learning
> C."

    That is not a universal belief.

 It doesn't take 10+ years to learn C to a degree where you can
> successfully write things like "I want to write an integer to a file"
> or whatever your random project of the week is.

<snicker>
What??

ROTFL. Have you heard of a killfile? I don't expect to hear from you again 
after this thread. Where the hell did you come from?

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


#27886

From"Bill Cunningham" <nospam@nspam.invalid>
Date2012-10-30 19:12 -0500
Message-ID<k6pms9$lns$1@dont-email.me>
In reply to#27882
tom st denis wrote:

> Who the fuck knows why they used it.

    I had a point but it's gone now.

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


#28176

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2012-11-10 06:49 -0800
Message-ID<b13c97a2-dd9c-41f1-b3a7-f6f402686123@l7g2000vbj.googlegroups.com>
In reply to#27862
On Oct 30, 10:11 pm, tom st denis <t...@iahu.ca> wrote:
> On Oct 30, 6:08 pm, "BartC" <b...@freeuk.com> wrote:
>
> > "tom st denis" <t...@iahu.ca> wrote in messagenews:3f556c91-92ab-4d83-96d2-7d7952a356ee@s18g2000yqh.googlegroups.com...
>
> > > On Oct 30, 5:50 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
> > >>   That's what I have been told.
>
> > > If you don't know that char s[] is equivalent to char *s by now you
> > > have to be trolling and are deserving of contempt.
>
> > But in certain contexts, they are not the same. The question is reasonable.
>
> As a function parameter?  They're entirely interchangeable.  It's
> convention to use the star

no it isna't

> but you can use [] if it floats your boat.
>
> Tom

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


#28213

FromOld Wolf <oldwolf@inspire.net.nz>
Date2012-11-11 14:37 -0800
Message-ID<4b5b8dda-0392-4a71-8625-88619f242093@vy11g2000pbb.googlegroups.com>
In reply to#27852
On Oct 31, 10:56 am, tom st denis <t...@iahu.ca> wrote:
> If you don't know that char s[] is equivalent to char *s by now you
> have to be trolling and are deserving of contempt.
>
> And frankly I don't get you.  Trolling comp.lang.c?  Do you know how
> specific that is?  Of the few 100,000 people on the planet who are
> aware of C you have to be one of the trolls?  Seriously?  Get a hobby.

Bill Cunningham has been posting rank beginner questions
to this newsgroup now for, what, 6 years?

It's hard to see how it could be anything other than trolling. Maybe
he
is addicted to the sense of community he feels when people respond to
his posts?

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


#28169

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2012-11-10 06:27 -0800
Message-ID<48585fb2-7907-4bd6-aaac-ee02bf6d4fb3@b19g2000vbt.googlegroups.com>
In reply to#27851
On Oct 30, 9:50 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
> tom st denis wrote:
> > Fuck off.
>
>     Go fuck yourself. That's what I have been told.

leave some context in you idiot.
who told you? And what did they tell you? (you tend to misquote people)

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


#27853

FromKeith Thompson <kst-u@mib.org>
Date2012-10-30 15:00 -0700
Message-ID<lnr4ofr572.fsf@nuthaus.mib.org>
In reply to#27848
"Bill Cunningham" <nospam@nspam.invalid> writes:
>     §1.9 page 29 has this function.
>
> int getline (char s[], int lim)
>
> Unless I'm missing something here to pass an array shoudn't that first 
> parameter be char *s ?

N1570 6.7.6.3p7.

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

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


#27866

From"Bill Cunningham" <nospam@nspam.invalid>
Date2012-10-30 18:18 -0500
Message-ID<k6pjnf$386$1@dont-email.me>
In reply to#27853
Keith Thompson wrote:

> N1570 6.7.6.3p7.

Is this the part your talking about Keith?
6.7.6.3 Function declarators (including prototypes)

Constraints




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


#27887

FromKeith Thompson <kst-u@mib.org>
Date2012-10-30 16:13 -0700
Message-ID<ln7gq7r1sc.fsf@nuthaus.mib.org>
In reply to#27848
"Bill Cunningham" <nospam@nspam.invalid> writes:
>     §1.9 page 29 has this function.
>
> int getline (char s[], int lim)
>
> Unless I'm missing something here to pass an array shoudn't that first 
> parameter be char *s ?

It depends on what you mean by "should".

The rest of this thread indicates that you're aware that this:
    int getline (char s[], int lim)
and this:
    int getline (char *s, int lim)
are equivalent.  This is implied by N1370 6.7.6.3 paragraph 7, or by the
corresponding paragraph in earlier versions or drafts of the C standard.

Apparently you were wondering about this as a style issue, though your
original question gave no hint of that (and nobody is going to assume
that you understand the language issue).

Personally, I dislike using array notation for pointer parameters;
in my opinion it obfuscates the fact that the parameter is really
a pointer.  But there are sound arguments for using it.  If I write:

    void func(char *s);

the intent could be either that s points to a single object of type
char, or that s points to the first element of an array of one or
more char elements.  Using array notation:

    void func(char s[]);

can make it clear to the reader that it's intended to point to the
first element of an array.  (I'd rather express this distinction
in a comment rather than using language syntax.)  Furthermore, C99
added features that let you express additional information between
the square brackets.  This:

    void func(char s[42]);

requires s to point to the first element of an array of *at least*
42 elements.  (This requirement is imposed on the caller, and it's
not enforced by the compiler; if you violate it, your program's
behavior is undefined.)

The standard itself uses array notation when defining the
two-parameter definition of main:

    int main(int argc, char *argv[]) { /* ... */ }

Again, I prefer to write:

    int main(int argc, char **argv) { /* ... */ }

It's interesting to note that the standard *doesn't* use array
notation for the <string.h> functions:

    size_t strlen(const char *s);

even though s must point to the first element of an array.  This is
arguably a slight inconsistency in the standard, but I don't think
it's worth worrying about.

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

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


#27891

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-10-30 23:31 +0000
Message-ID<0.197d8109ec2cea54419e.20121030233117GMT.874nlb1qre.fsf@bsb.me.uk>
In reply to#27887
Keith Thompson <kst-u@mib.org> writes:
<snip>
> [...]  Furthermore, C99
> added features that let you express additional information between
> the square brackets.  This:
>
>     void func(char s[42]);

I think you mean func(char s[static 42]);

> requires s to point to the first element of an array of *at least*
> 42 elements.

<snip>
-- 
Ben.

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


#27897

FromKeith Thompson <kst-u@mib.org>
Date2012-10-30 17:45 -0700
Message-ID<ln390vqxjj.fsf@nuthaus.mib.org>
In reply to#27891
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Keith Thompson <kst-u@mib.org> writes:
> <snip>
>> [...]  Furthermore, C99
>> added features that let you express additional information between
>> the square brackets.  This:
>>
>>     void func(char s[42]);
>
> I think you mean func(char s[static 42]);

Yes, you're right.

>> requires s to point to the first element of an array of *at least*
>> 42 elements.
>
> <snip>

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

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


#27903

FromAnand Hariharan <mailto.anand.hariharan@gmail.com>
Date2012-10-31 05:43 -0700
Message-ID<30f35554-1796-4cde-a221-3c4d26f9e345@sh1g2000pbc.googlegroups.com>
In reply to#27891
On Oct 30, 6:31 pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> Keith Thompson <ks...@mib.org> writes:
>
> <snip>
>
> > [...]  Furthermore, C99
> > added features that let you express additional information between
> > the square brackets.  This:
>
> >     void func(char s[42]);
>
> I think you mean func(char s[static 42]);
>
> > requires s to point to the first element of an array of *at least*
> > 42 elements.
>
> <snip>


Is there a document (that can be read/understood by ordinary mortals)
that explains all the different meanings of 'static'?

- Anand

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


#27905

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-10-31 13:33 +0000
Message-ID<0.34b724ae6407d900dc4c.20121031133356GMT.87liemzry3.fsf@bsb.me.uk>
In reply to#27903
Anand Hariharan <mailto.anand.hariharan@gmail.com> writes:

> On Oct 30, 6:31 pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
>> Keith Thompson <ks...@mib.org> writes:
>>
>> <snip>
>>
>> > [...]  Furthermore, C99
>> > added features that let you express additional information between
>> > the square brackets.  This:
>>
>> >     void func(char s[42]);
>>
>> I think you mean func(char s[static 42]);
>>
>> > requires s to point to the first element of an array of *at least*
>> > 42 elements.
>>
>> <snip>
>
>
> Is there a document (that can be read/understood by ordinary mortals)
> that explains all the different meanings of 'static'?

:-)  I am not aware of one.

There are only two positions in which static can appear: the "old" one
in an ordinary declaration and this new one (well, new since 1999) in a
parameter declaration.  It feels like, more because the effect of it
appearing in plain a declaration varies a little depending on where that
declaration is: it always gives the declared identifier internal
linkage, but in a declaration at block scope it also gives the object
static storage duration.

-- 
Ben.

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


#27907

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-10-31 10:27 -0400
Message-ID<50913551.3030206@verizon.net>
In reply to#27905
On 10/31/2012 09:33 AM, Ben Bacarisse wrote:
> Anand Hariharan <mailto.anand.hariharan@gmail.com> writes:
...
>> Is there a document (that can be read/understood by ordinary mortals)
>> that explains all the different meanings of 'static'?
> 
> :-)  I am not aware of one.
> 
> There are only two positions in which static can appear: the "old" one
> in an ordinary declaration and this new one (well, new since 1999) in a
> parameter declaration.  It feels like, more because the effect of it
> appearing in plain a declaration varies a little depending on where that
> declaration is: it always gives the declared identifier internal
> linkage, but in a declaration at block scope it also gives the object
> static storage duration.

It only gives identifiers internal linkage at file scope; block scope
objects have no linkage unless declared 'extern', in which case they
have external linkage. (6.2.2p7)

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


#27909

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-10-31 16:11 +0000
Message-ID<0.afe924733505dd634fc8.20121031161124GMT.878vamzknn.fsf@bsb.me.uk>
In reply to#27907
James Kuyper <jameskuyper@verizon.net> writes:

> On 10/31/2012 09:33 AM, Ben Bacarisse wrote:
>> Anand Hariharan <mailto.anand.hariharan@gmail.com> writes:
> ...
>>> Is there a document (that can be read/understood by ordinary mortals)
>>> that explains all the different meanings of 'static'?
>> 
>> :-)  I am not aware of one.
>> 
>> There are only two positions in which static can appear: the "old" one
>> in an ordinary declaration and this new one (well, new since 1999) in a
>> parameter declaration.  It feels like, more because the effect of it
>> appearing in plain a declaration varies a little depending on where that
>> declaration is: it always gives the declared identifier internal
>> linkage, but in a declaration at block scope it also gives the object
>> static storage duration.
>
> It only gives identifiers internal linkage at file scope; block scope
> objects have no linkage unless declared 'extern', in which case they
> have external linkage. (6.2.2p7)

Quote right.  All it does for a block-scope object is change its storage
duration.

-- 
Ben.

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


#28105

FromAnand Hariharan <mailto.anand.hariharan@gmail.com>
Date2012-11-07 14:53 -0800
Message-ID<950313d5-67b5-43ab-a3ed-80613c6fedaa@q5g2000pbk.googlegroups.com>
In reply to#27909
On Oct 31, 10:11 am, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> James Kuyper <jameskuy...@verizon.net> writes:
> > On 10/31/2012 09:33 AM, Ben Bacarisse wrote:
> >> Anand Hariharan <mailto.anand.hariha...@gmail.com> writes:
> > ...
> >>> Is there a document (that can be read/understood by ordinary mortals)
> >>> that explains all the different meanings of 'static'?
>
> >> :-)  I am not aware of one.
>
> >> There are only two positions in which static can appear: the "old" one
> >> in an ordinary declaration and this new one (well, new since 1999) in a
> >> parameter declaration.  It feels like, more because the effect of it
> >> appearing in plain a declaration varies a little depending on where that
> >> declaration is: it always gives the declared identifier internal
> >> linkage, but in a declaration at block scope it also gives the object
> >> static storage duration.
>
> > It only gives identifiers internal linkage at file scope; block scope
> > objects have no linkage unless declared 'extern', in which case they
> > have external linkage. (6.2.2p7)
>
> Quote right.  All it does for a block-scope object is change its storage
> duration.
>

Thank you, Ben and James.

sincerely,
- Anand

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


#27908

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-10-31 10:38 -0400
Message-ID<509137DC.6020007@verizon.net>
In reply to#27903
On 10/31/2012 08:43 AM, Anand Hariharan wrote:
> On Oct 30, 6:31 pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
>> Keith Thompson <ks...@mib.org> writes:
...
>>> [...]  Furthermore, C99
>>> added features that let you express additional information between
>>> the square brackets.  This:
>>
>>>     void func(char s[42]);
>>
>> I think you mean func(char s[static 42]);
>>
>>> requires s to point to the first element of an array of *at least*
>>> 42 elements.
>>
>> <snip>
> 
> 
> Is there a document (that can be read/understood by ordinary mortals)
> that explains all the different meanings of 'static'?

I've read and understood the standard; but perhaps I shouldn't consider
myself an "ordinary mortal"?

In themselves, the other meanings of 'static' aren't very complicated:
At file scope, the 'static' keyword gives function or object identifiers
internal linkage. (6.2.2p3)
At block scope, it gives objects static storage duration. (6.2.4p3)

If you need an explanation of what "internal linkage" or "static storage
duration" mean, that's a little more complicated.

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


#27892

From"Bill Cunningham" <nospam@nspam.invalid>
Date2012-10-30 19:39 -0500
Message-ID<k6poed$tvh$1@dont-email.me>
In reply to#27887
Keith Thompson wrote:

> It depends on what you mean by "should".
>
> The rest of this thread indicates that you're aware that this:
>    int getline (char s[], int lim)
> and this:
>    int getline (char *s, int lim)
> are equivalent.  This is implied by N1370 6.7.6.3 paragraph 7, or by
> the corresponding paragraph in earlier versions or drafts of the C
> standard.
>
> Apparently you were wondering about this as a style issue, though your
> original question gave no hint of that (and nobody is going to assume
> that you understand the language issue).
>
> Personally, I dislike using array notation for pointer parameters;
> in my opinion it obfuscates the fact that the parameter is really
> a pointer.  But there are sound arguments for using it.  If I write:
>
>    void func(char *s);

    I agree.

> the intent could be either that s points to a single object of type
> char, or that s points to the first element of an array of one or
> more char elements.  Using array notation:
>
>    void func(char s[]);
>
> can make it clear to the reader that it's intended to point to the
> first element of an array.  (I'd rather express this distinction
> in a comment rather than using language syntax.)  Furthermore, C99
> added features that let you express additional information between
> the square brackets.  This:
>
>    void func(char s[42]);
>
> requires s to point to the first element of an array of *at least*
> 42 elements.  (This requirement is imposed on the caller, and it's
> not enforced by the compiler; if you violate it, your program's
> behavior is undefined.)
>
> The standard itself uses array notation when defining the
> two-parameter definition of main:
>
>    int main(int argc, char *argv[]) { /* ... */ }
>
> Again, I prefer to write:
>
>    int main(int argc, char **argv) { /* ... */ }
>
> It's interesting to note that the standard *doesn't* use array
> notation for the <string.h> functions:
>
>    size_t strlen(const char *s);
>
> even though s must point to the first element of an array.  This is
> arguably a slight inconsistency in the standard, but I don't think
> it's worth worrying about.

    I just didn't appreciate being attacked and accused of not knowing 
things I know obviously. I am not a newbie no but it was *meant* as a style 
question as you say.

Bill

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


#27898

FromKeith Thompson <kst-u@mib.org>
Date2012-10-30 17:51 -0700
Message-ID<lny5inpipl.fsf@nuthaus.mib.org>
In reply to#27892
"Bill Cunningham" <nospam@nspam.invalid> writes:
[...]
>     I just didn't appreciate being attacked and accused of not knowing 
> things I know obviously. I am not a newbie no but it was *meant* as a style 
> question as you say.

Not to defend the attacks you've been subjected to in this thread,
but when I read your original question I did assume that you weren't
aware that "char foo[]" and "char *foo" are equivalent as parameter
definitions.  It seemed to me to be a reasonable assumption based
on your history. In any case, the exact same question could have
been asked by someone who *didn't* know about the equivalence.

Wording your question more clearly might have avoided a lot of
misunderstanding.

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

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


#27913

From"Bill Cunningham" <nospam@nspam.invalid>
Date2012-10-31 13:47 -0500
Message-ID<k6ro77$bok$1@dont-email.me>
In reply to#27898
Keith Thompson wrote:
> Not to defend the attacks you've been subjected to in this thread,
> but when I read your original question I did assume that you weren't
> aware that "char foo[]" and "char *foo" are equivalent as parameter
> definitions.  It seemed to me to be a reasonable assumption based
> on your history. In any case, the exact same question could have
> been asked by someone who *didn't* know about the equivalence.
>
> Wording your question more clearly might have avoided a lot of
> misunderstanding.

    I thought in other posts and as long as I've been around that it would 
be a reasonable assumption that in the very least I would know the sameness 
and differences about pointers and arrays. Agreed my wording could've been 
better but alot of that has always been my problem. I didn't know about the 
word "convention" but I know I had been told that in the case of a parameter 
declartion for taking an array was a pointer to whatever. I also assume that 
kandr2 isn't wrong. So I wanted to clear up the confusion. I believe now 
that it is legal C but not conventional.

Bill

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


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

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


csiph-web