kandr2 question

B

Bill Cunningham

SG said:
Why?

Personally, I prefer to use [] when declaring a function if the
function potentially wants "more than thing" (i.e. does pointer
arithmetic on it to access more than one object etc). I prefer *
otherwise. It makes the code kind of self-documenting to some degree.

One could argue that * and [] is an irregular aspect of the language
and one should avoid it just to make it easier for people to read the
code who don't know the rule that the compiler replaces the top-level
[] in function parameter types with *.

But then again, we still have array-to-pointer decay which is
something newbies have to deal with eventually... So much for
regularity.

Cheers!
SG

I guess to each his/her own.

Bill
 
B

Barry Schwarz

Barry said:
Granted that the parameter COULD be changed as you describe, why do
you think it SHOULD be changed?
[snip]
n1570.

What does the hybrid version of the Infinity Q45 automobile have to do with this discussion?

There is no n1570. All the numbers under the N are in the range of 31 to 45.

And in the draft standard, the word "should" appears 80 times. Not one of those is related to the form a a function parameter. Maybe you should actually read it sometime.

If you are just going to throw random words together, do it in alt.anagrams where it can possibly lead to an interesting thread.
 
P

Phil Carmody

Barry Schwarz said:
Barry said:
Granted that the parameter COULD be changed as you describe, why do
you think it SHOULD be changed?
[snip]
n1570.

What does the hybrid version of the Infinity Q45 automobile have to do with this discussion?

There is no n1570. All the numbers under the N are in the range of 31 to 45.

And in the draft standard, the word "should" appears 80 times. Not one of those is related to the form a a function parameter. Maybe you should actually read it sometime.

If you are just going to throw random words together, do it in alt.anagrams where it can possibly lead to an interesting thread.

No! Please - we already have one clue-resistent loon in a.a, we don't need another (and f/ups set).

Poster Bill Cunningham =
Bing "Null pointer chasm"

Phil
 
B

Bill Cunningham

Keith said:
As it should be. You've claimed repeatedly that you understood that
"char s[]" and "char *s" are equivalent as parameter definitions.

Yes I do.

You claimed that your original question was about stylistic
conventions. Now you tell us that you thought "char s[]" would
be illegal. I see no reasonable explanation for this inconsistency.
I got it straight
now though.

When this thread began I thought style was part of the standard. And I
do have a n1570.pdf. Convention came to be known as programmer's option.
Standard or a best current practice was what I believed to be using char *s
instead of char s[].
Does that help any? Do you know know what I've been thinking. As I said
I even regret this thread now.

Bill
 
B

Bill Cunningham

Barry said:
There is no n1570. All the numbers under the N are in the range of
31 to 45.

And in the draft standard, the word "should" appears 80 times. Not
one of those is related to the form a a function parameter. Maybe
you should actually read it sometime.

If you are just going to throw random words together, do it in
alt.anagrams where it can possibly lead to an interesting thread.

I have n1570.pdf and n1256.pdf which is older.

Bill
 
B

Barry Schwarz

N

Nick Keighley

    Go **** 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)
 
N

Nick Keighley

You asked if a char s[] inside a parameter list should instead be char
*s.
The answer is no.  It doesn't have to be.

I have never seen good function prototypes except these examples declare an
array definition as char s[] in the prototype. Are you looking at a babie's
code? They must be writing like this is kandr2 to simplify things.

I'm no baby and I often use array syntax
 
N

Nick Keighley

tom said:
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.

    Of course I know that Dick. What's that got to do with anything? Read
the standard.
what?
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.

    You're the one dropping a troll.
 
N

Nick Keighley

tom st denis wrote:
CONTEXT!!!!!!!!!!!!!!!
And since clearly you seem to know this [judging by your reply here]
why the <expletive> are you asking?

None of your <expletive> Business and *I* was right. But that's not my point.

if a question makes no sense then knowing the reason for asking it may
help work what the question is really about. You were not right you
were 100% wrong.
 
N

Nick Keighley

tom said:
It's convention to use the star but that's not mandatory.  Just like
you could write
char a[4];
a[3] = 4;

3[a] = 4;
They're equivalent C code.  Most people would use the former instead
of the latter even though they have the same effect.

In my original question I was asking about convention.

and the answer is it's a convention that isn't adhered to very widely.
Maybe most code uses it but nowhere near all. As I remarked earlier I
use array syntax myself if I expect most callers to be passing an
array. I sometimes think it makes the intent of the code clearer.
 
N

Nick Keighley

tom said:
tom st denis wrote:
It's convention to use the star but that's not mandatory. Just like
you could write
char a[4];
a[3] = 4;
Or
3[a] = 4;
They're equivalent C code. Most people would use the former instead
of the latter even though they have the same effect.
Tom
In my original question I was asking about convention.
No you didn't.  Here's your original question
And the answer is no.  It's not an error, it can be "char s[]" if the
author wants to write that way.

Let me write what was intended in my mind,
Unless I'm missing something here to pass an array shoudn't that
first parameter be char *s [by convention]?

And the answer is no. It should be char *s [by convention] of course.

no.
 
N

Nick Keighley

    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.

except you seem to make no attempt to compensate for your alleged
problems. I for instance combat a poor memory by taking notes and
*using* them.
 
N

Nick Keighley

  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
 
N

Nick Keighley

[...]
    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.

the sun will be a cold cinder before Bill manages to ask a clear, well
thought out question
 
N

Nick Keighley

Keith said:
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.

a point I don't agree with
 
N

Nick Keighley

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

adapting getline 77
Chatbot 0
GET NEIL DEGRASSES TYSON, I ripped a hole with this one... 0
Command Line Arguments 0
TF-IDF 2
don't understand the "&&" in K&R2 example 2
Help in hangman game 1
Function Help 1

Members online

Forum statistics

Threads
474,077
Messages
2,570,567
Members
47,204
Latest member
abhinav72673

Latest Threads

Top