why do the following crash

P

parag_paul

File1.c

int arr[80];

File2.c

extern int *arr;
int main()
{
arr[1] = 100;
return 0;
}
 
R

Richard

Philip Potter said:
File1.c

int arr[80];

File2.c

extern int *arr;
int main()
{
arr[1] = 100;
return 0;
}

Did you read the FAQ? You have just asked question 6.1, and if you go
to http://c-faq.com/ you will get your answer.

Philip

Will you be replying to every question here with a pointer to the FAQ?

If so possibly you would like to just automate your replies?

Hint : not every programmer that comes here can memorise the entire FAQ
nor can they always find the necessary section of the FAQ.
 
E

Ed Prochak

Philip Potter said:
File1.c
int arr[80];
File2.c
extern int *arr;
int main()
{
arr[1] = 100;
return 0;
}
Did you read the FAQ? You have just asked question 6.1, and if you go
tohttp://c-faq.com/you will get your answer.

Will you be replying to every question here with a pointer to the FAQ?

Why shouldn't he, if the question really is a FAQ?
If so possibly you would like to just automate your replies?

Are you offering to do it? While the scope of the problem is more
limited, the problem of interpreting human language automatically
appears to be intractable.
Hint : not every programmer that comes here can memorise the entire FAQ
nor can they always find the necessary section of the FAQ.

The FAQ is a nice reference. No one is expected to memorize it but it
would do good to read it once in a while. (I think I am due for a
refresher.)
Ed
 
R

Richard

Ed Prochak said:
Philip Potter said:
(e-mail address removed) wrote:
File1.c
int arr[80];

extern int *arr;
int main()
{
arr[1] = 100;
return 0;
}
Did you read the FAQ? You have just asked question 6.1, and if you go
tohttp://c-faq.com/you will get your answer.

Will you be replying to every question here with a pointer to the FAQ?

Why shouldn't he, if the question really is a FAQ?

No problem if you take the time to answer too IMO.
Are you offering to do it? While the scope of the problem is more
limited, the problem of interpreting human language automatically
appears to be intractable.

I agree.

But a naive solution would be simply auto reply to each new post

"have you read the FAQ : here ..."
The FAQ is a nice reference. No one is expected to memorize it but it
would do good to read it once in a while. (I think I am due for a
refresher.)
Ed

Off you go then. No one is stopping you. I have too. It doesn't mean I
dont find it easier and more social to ask a human being.

In your haste you seem to have misunderstood. My point is that 99.99% of
questions here are answered in one way or other by the FAQ,

Simply questioning people as to whether they read it and then somewhat
pompously pointing them there makes the group pretty much redundant.

By ALL means post a link to the FAQ, but add some personal explanation
too.
 
M

Morris Dovey

Richard said:
Will you be replying to every question here with a pointer to the FAQ?

If so possibly you would like to just automate your replies?

Richard, I think you just had a great idea!
Hint : not every programmer that comes here can memorise the entire FAQ
nor can they always find the necessary section of the FAQ.

That's true. Lacking automated response software, it's good to
have folks like Philip around to help people find ready-made,
accurate answers.

About your automated response idea - care to take a try at it? It
could be an interesting project!
 
W

Willem

Richard wrote:
) But a naive solution would be simply auto reply to each new post
)
) "have you read the FAQ : here ..."

He pointed to a *specific item* in the FAQ.

) In your haste you seem to have misunderstood. My point is that 99.99% of
) questions here are answered in one way or other by the FAQ,
)
) Simply questioning people as to whether they read it and then somewhat
) pompously pointing them there makes the group pretty much redundant.

He pointed to the *specific part* of the FAQ that answered the question.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
K

Kenny McCormack

Richard wrote:
) But a naive solution would be simply auto reply to each new post
)
) "have you read the FAQ : here ..."

He pointed to a *specific item* in the FAQ.

Yes. We all understand that.
) In your haste you seem to have misunderstood. My point is that 99.99% of
) questions here are answered in one way or other by the FAQ,
)
) Simply questioning people as to whether they read it and then somewhat
) pompously pointing them there makes the group pretty much redundant.

He pointed to the *specific part* of the FAQ that answered the question.

Yes. We all understand that.

And, yes, all also understand that that is the part that would be a
little tricky about implementing the auto-responder. Save that for
Version 2.0.

In the meantime, an auto-responder that simply greets every new thread
(by a newbie - the program would keep a list of people to exclude from
treatment) with "The answer is in the FAQ. Please see the FAQ at: <URL>"
would be very nice and save certain people (e.g., Bwian) from having to
do it manually.
 
B

Bartc

File1.c

int arr[80];

File2.c

extern int *arr;
int main()
{
arr[1] = 100;
return 0;
}

The declarations for the arr variable don't match.

Try extern int arr[80] in File2.c.

(I know arrays and pointers are /supposed/ to be interchangeable. But there
is a subtle difference between: int a[80] and int *a)
 
P

Philip Potter

Bartc said:
File1.c

int arr[80];

File2.c

extern int *arr;
int main()
{
arr[1] = 100;
return 0;
}

The declarations for the arr variable don't match.

Try extern int arr[80] in File2.c.

(I know arrays and pointers are /supposed/ to be interchangeable. But there
is a subtle difference between: int a[80] and int *a)

Arrays and pointers aren't supposed to be interchangable. They don't
represent the same concept.

An array of 5 ints is a collection of 5 ints in contiguous memory.

A pointer-to-int is an value which represents the location of an int in
memory.

The confusion arises because array accesses are defined in terms of
pointers. This means that in an expression like 'arr[2]', the identifier
'arr' which refers to an array "decays" to a pointer-to-first-member;
then the subscript operator [] is syntactic sugar for '*(arr + 2)', a
pointer arithmetic and dereference operation.

Naturally, in an expression like 'ptr[2]', the rules are the same,
except that 'ptr' is already a pointer value and doesn't need to
"decay". If 'ptr' points to an element at least 3 before the end of an
array, then this is a valid expression.

The FAQ has a very good description of the difference between arrays and
poitners in question 6.2.

Philip
 
E

Ed Prochak

Yes. We all understand that.



Yes. We all understand that.

It was not clear from your posts that you understood that.
And, yes, all also understand that that is the part that would be a
little tricky about implementing the auto-responder. Save that for
Version 2.0.

In the meantime, an auto-responder that simply greets every new thread
(by a newbie - the program would keep a list of people to exclude from
treatment) with "The answer is in the FAQ. Please see the FAQ at: <URL>"
would be very nice and save certain people (e.g., Bwian) from having to
do it manually.


But not every new thread by new comers has an answer in the FAQ.

BTW I noticed that you only responded to RH complaining about his
post. You never bothered to answer the OP. Maybe next time you will
lead by example rather than complain?
 
W

Willem

Ed wrote:
) On Mar 31, 11:22 am, (e-mail address removed) (Kenny McCormack)
) wrote:
)> Yes. We all understand that.
)
) It was not clear from your posts that you understood that.

You're confusing Kenny-the-Troll, who is nothing but a troll,
with Just-Richard, who's an okay chap although he often has
opinions I don't share.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
R

Richard

Willem said:
Ed wrote:
) On Mar 31, 11:22 am, (e-mail address removed) (Kenny McCormack)
) wrote:
)> Yes. We all understand that.
)
) It was not clear from your posts that you understood that.

You're confusing Kenny-the-Troll, who is nothing but a troll,
with Just-Richard, who's an okay chap although he often has
opinions I don't share.


SaSW, Willem

Actually I think Kenny is an ok chap too. He and his type (and I am
similar) are required to stop certain elements getting too carried away
with their own self importance.
 
S

Serve L

Richard said:
Actually I think Kenny is an ok chap too. He and his type (and I am
similar) are required to stop certain elements getting too carried away
with their own self importance.

What do you think about people who spell the first 2 letters of their name
with a capital? :p
 
M

Morris Dovey

Richard said:
Actually I think Kenny is an ok chap too. He and his type (and I am
similar) are required to stop certain elements getting too carried away
with their own self importance.

Umm. How would you rate the self-importance of a person who
claims sufficient moral superiority stand in judgement of any
group of strangers?
 
R

Richard

Morris Dovey said:
Umm. How would you rate the self-importance of a person who
claims sufficient moral superiority stand in judgement of any
group of strangers?

I have no idea which self righteous crusade you are now, but like many
others I can only call it as I see it. And there is a rather gaping
divide between been an arrogant arse and putting people down all the
time and saying "Hey you, who the hell do you think you are? Calm down
and give someone else a chance here". If you can't see the fundamental
difference between the two approaches then there isn't much point
trying to explain it to you I am afraid. A bit like trying to get
through to certain elements here that just because they had once or
twice found a bug from a printout on 500,000 lines of code that that
does not invalidate good practice in using a debugger responsibly and
skillfully in order to save time and money.
 
M

Morris Dovey

Richard said:
I have no idea which self righteous crusade you are now, but like many
others I can only call it as I see it. And there is a rather gaping
divide between been an arrogant arse and putting people down all the
time and saying "Hey you, who the hell do you think you are? Calm down
and give someone else a chance here". If you can't see the fundamental
difference between the two approaches then there isn't much point
trying to explain it to you I am afraid. A bit like trying to get
through to certain elements here that just because they had once or
twice found a bug from a printout on 500,000 lines of code that that
does not invalidate good practice in using a debugger responsibly and
skillfully in order to save time and money.

Just looking for a little clarification - and guess I got it. :)
 
R

Richard Heathfield

Morris Dovey said:
Umm. How would you rate the self-importance of a person who
claims sufficient moral superiority stand in judgement of any
group of strangers?

Who cares? It isn't *self*-importance that matters in comp.lang.c. The
trolls think they're important (i.e. they are self-important), as
Just-Richard demonstrates above with words like "required", but nobody
else does.

If the trolls ever get around to learning how to explain C to other people
instead of filling the group with their bile, maybe they will become
*genuinely* important. If it ever occurs and you happen to notice, do let
me know.
 
M

Morris Dovey

Richard said:
If the trolls ever get around to learning how to explain C to other people
instead of filling the group with their bile, maybe they will become
*genuinely* important. If it ever occurs and you happen to notice, do let
me know.

I've been watching. I figure that if they hang around long
enough, they won't be able to help learning enough to help
/somebody/ with /something/.

:)
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top