Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > kandr2 question

Reply
Thread Tools

kandr2 question

 
 
Bill Cunningham
Guest
Posts: n/a
 
      10-31-2012
Lew Pitcher wrote:

> Sidenote: /This/ http://www.velocityreviews.com/forums/(E-Mail Removed)d doesn't sound like the usual
> Bill that we all know. Either something has changed drastically with
> Bill, or the group has been trolled by someone posing as Bill.


What do you mean? I'm starting to get tired of being misrepresented and
accused of things wrongly. I have problems focusing and other mental issues.
I'm not whining but there's a reason I catch on slow. And a lack of things
to do with C except the UNIX API. I'm thinking of an example cbc_crypt in
the API for n*xs that takes arrays and the prototypes are declared as
pointers to char.

Bill


 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      10-31-2012
"Bill Cunningham" <(E-Mail Removed)> 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) (E-Mail Removed) <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"
 
Reply With Quote
 
 
 
 
BartC
Guest
Posts: n/a
 
      10-31-2012


"Keith Thompson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Bill Cunningham" <(E-Mail Removed)> 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.


There *is* something funny about char[] and char* being equivalent here.
It's apparent when doing automatic translators of type specifications (from
English, say) to C.

Translating 'array of char' to C is just 'char[]' (0 indirections) for an
ordinary declaration.

And 'pointer to array of char' is 'char(*)[]' (1 indirection). There's a
natural progression.

Now try and use these translations for function parameters; there's an
off-by-one error! A char(*)[] will give two indirections, while char[] gives
you one.

I suppose that since a true char[] parameter would allow pass-by-value
arrays, it was decided to make it mean something else. But it might have
been more useful to actually let it mean that, and to raise an error if
someone tried to use it without adding something more to it (such as
char(*)[]).

It would have made automatic translators simpler too. (Actually there was
bug in my translator because of this. It still worked though, because so
many casts were used elsewhere to make things right; I could have used float
instead of char* or char[] and it would have worked..)

--
Bartc

 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      10-31-2012
On Tuesday, October 30, 2012 2:41:06 PM UTC-7, Bill Cunningham wrote:
> 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 ? Bill


Granted that the parameter COULD be changed as you describe, why do you think it SHOULD be changed?

If you are going to ask questions about text in a document, you should at least quote the document accurately. Yes, the change you made was harmless but you are in no position to make that determination in the general case.
 
Reply With Quote
 
Anand Hariharan
Guest
Posts: n/a
 
      10-31-2012
On Oct 30, 6:31*pm, Ben Bacarisse <(E-Mail Removed)> wrote:
> Keith Thompson <(E-Mail Removed)> 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
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      10-31-2012
Anand Hariharan <(E-Mail Removed)> writes:

> On Oct 30, 6:31*pm, Ben Bacarisse <(E-Mail Removed)> wrote:
>> Keith Thompson <(E-Mail Removed)> 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.
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      10-31-2012
On 10/31/2012 09:33 AM, Ben Bacarisse wrote:
> Anand Hariharan <(E-Mail Removed)> 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)

 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      10-31-2012
On 10/31/2012 08:43 AM, Anand Hariharan wrote:
> On Oct 30, 6:31 pm, Ben Bacarisse <(E-Mail Removed)> wrote:
>> Keith Thompson <(E-Mail Removed)> 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.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      10-31-2012
James Kuyper <(E-Mail Removed)> writes:

> On 10/31/2012 09:33 AM, Ben Bacarisse wrote:
>> Anand Hariharan <(E-Mail Removed)> 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.
 
Reply With Quote
 
Phil Carmody
Guest
Posts: n/a
 
      10-31-2012
Keith Thompson <(E-Mail Removed)> writes:
> "Bill Cunningham" <(E-Mail Removed)> writes:

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


But why would a troll do that if he knows he's more likely
to rack up a whole bunch more strokes if he keeps things
badly worded?

Phil
--
Regarding TSA regulations:
How are four small bottles of liquid different from one large bottle?
Because four bottles can hold the components of a binary liquid explosive,
whereas one big bottle can't. -- camperdave responding to MacAndrew on /.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments