K&R2 , exercise 7.6

E

Eligiusz Narutowicz

user923005 said:
If a well prepared and correct answer is found in the FAQ, wouldn't it
be a nice place to point people?


Brian posts here to be helpful. On those occasions when something is
not contained in the FAQ, he will post pertinant information regarding
the issue at hand.

Pretty much all usenet groups have FAQs and it is simple common
courtesy to read them before posting.
http://www.uiowa.edu/~writingc/handouts/netiquette.htm
http://www.albion.com/bookNetiquette/0963702513p32.html
http://www.walthowe.com/navnet/faq/guidelines.html
http://en.wikipedia.org/wiki/FAQ

HTH

I am sorry but I know what a FAQ is. But one can point nearly all people
to the FAQ. Nicholas was abrupt I thought in his "have you bothered to
read the faq" comment. It was just my opinions that this is not the
right answer. One can always nicely refer people to it, but people can
not always find what they need if they dont know what the problem
is. Just my 2c of course. I think it is rude and you may of course think
otherwise. I didnt see Brian posting too much help only telling people
off so sorry if I was wrong.
 
U

user923005

I am sorry but I know what a FAQ is. But one can point nearly all people
to the FAQ. Nicholas was abrupt I thought in his "have you bothered to
read the faq" comment.

One problem with printed media is that it is hard to judge intent and
feeling. Sometimes we read insult between the lines. That is simply
human nature. The fundamental rule of posting on the internet is:
1. Before posting to a USENET news group, grow a skin at least two
inches (five centimeters) thick.
It was just my opinions that this is not the
right answer. One can always nicely refer people to it, but people can
not always find what they need if they dont know what the problem
is.

Perhaps not. But it is a good idea to try that first.
Just my 2c of course. I think it is rude and you may of course think
otherwise.

It is never rude to refer people to the FAQ (unless it is done in this
way):
"READ THE FAQ YOU #@$%&*~ WHINGING TWIT!"
On the other hand, it is rude to post to a USENET news group without
reading the FAQ.
Some people don't know that, so we say things like:
"Read the FAQ, and you'll get whiter teeth and fresher breath!"
and:
"Why not read the FAQ? David Beckham read it and look at him now!"
I didnt see Brian posting too much help only telling people
off so sorry if I was wrong.

He has been posting here for quite a long time.
 
D

Default User

I think that is very obvious.

Is it? What DO you think the purpose is?
I don't know your point?

My point is, the FAQs are there for a reason, and that is to answer the
common questions.
So you will
only point people to the FAQ? Why do you post here then?

Because not all situations are covered by the FAQs, of course.




Brian
 
K

Keith Thompson

Eligiusz Narutowicz said:
I am sorry but I know what a FAQ is. But one can point nearly all people
to the FAQ. Nicholas was abrupt I thought in his "have you bothered to
read the faq" comment. It was just my opinions that this is not the
right answer. One can always nicely refer people to it, but people can
not always find what they need if they dont know what the problem
is. Just my 2c of course. I think it is rude and you may of course think
otherwise. I didnt see Brian posting too much help only telling people
off so sorry if I was wrong.

Many questions are answered in the FAQ, but not all are. Thus the FAQ
and the newsgroup nicely complement each other. As I'm sure you know.

To be precise, what Nick wrote (about 7 articles upthread from this
one) was not "have you bothered to read the faq", but "Have you read
the comp.lang.c FAQ?". It was a reasonable question in context, and I
saw nothing rude about it. It was in direct response to an article in
which a poster badly misstated the possible expansions of the NULL
macro; that article in turn was in direct response to another article,
which it quoted, in which two of the likely expansions of the NULL
macro had been stated correctly. IMHO Nick showed admirable restraint
given the circumstances.

More generally, it could be argued that flaming someone for posting
without reading the FAQ is rude. It could also be argued that posting
without reading the FAQ is rude. I will not state a position on
either of those questions. There are posters here who are, in my
opinion, repeatedly and unnecessarily rude. There are others who are,
in my opinion, falsely accused of being unnecessarily rude. I haven't
found discussing the issue to be a productive use of my time or of the
newsgroup's bandwidth.

My advice: try not to be offensive, and try not to be offended.
 
A

arnuld

no! NULL can be defined as ((void*)0) (note the zero at the end).
Have you read the comp.lang.c FAQ?


I did read the FAQ but the concept of NULL, NUL, '\0', ((void*) 0) and 0
is too complex and confusing to be grasped by oneself by just reading the
FAQs
 
A

arnuld

That is almost always a bad idea, because it can suppress diagnostic
messages about type matching violations.

well, the programmer knows that he *intentionally* casted the type.


0 is a null pointer constant. NULL is a null pointer constant. Each of
the above definitions gives buffer a value that is a null pointer.

from FAQ, I can conclude that, use of NULL is ok where I need a <void*>
and for everything else I can use a 0 (zero).

int m = 6;
int m = 3 + 3;

Are these equivalent? Do they have the same effect on m? If not, how do
they vary? What value will m get in the second definition that is
somehow different to the value it gets in the first? Thinking about this
very similar issue should enable you to understand the null pointer
assignments quoted above.


compiler will initialize <m> to a vale of 6. Compiler will get there
differently in both expressions but the end result will be <m> will be
equal 6.

Right ?
 
A

arnuld

no! NULL can be defined as ((void*)0) (note the zero at the end).
Have you read the comp.lang.c FAQ?


with some hard-thought I came to understand the distinction between NULL
and 0:


1.) In case of pointers, use NULL.
2 .) In cases where integral zero is requires, use 0.

except these 2 points, to me, every other discussion about NULL and 0 does
not seem important to me from programming in C perspective.
 
B

Barry Schwarz

*buff = 0;

puts a zero at the place pointed by pointer.

char *buffer = NULL;
char *buffer = 0;


different in what context ? Both are same as of value they contain:



#include <stdio.h>


int main(void) {

char *buffer = 0;
char *buffer2 = NULL;

printf("%s\n%s\n", buffer, buffer2);

Obviously you wanted to do something else rather than invoke undefined
behavior here. Did you mean to use %p instead of %s? If so, it would
be a good to acquire the habit of casting the pointers to void* (even
though a char* would work without the cast).
return 0;
}

============ OUTPUT ===============
/home/arnuld/programs/C $ gcc -ansi -pedantic -Wall -Wextra test.c
/home/arnuld/programs/C $ ./a.out
(null)
(null)
/home/arnuld/programs/C $





:)


Remove del for email
 
S

santosh

arnuld said:
I really meant %s because I am providing printf an array, whether
empty or full and you do see that its prints without any problem:

No. That's GNU C specific behaviour. You are confused between
initialising a pointer and later assigning to it. This

char *buf = 0;

is a declaration with an initialisation. It declares buf to a char * and
sets it to 0, which in a pointer context is automatically converted to
a null pointer value. buf is, after this initialisation, a null
pointer, something that is never legal to deference. The %s format
specifier needs a valid pointer pointing to a string, or a single null
character. The behaviour is undefined if a null pointer is passed to
it. It so happens that the GNU C compiler prints (null), but some other
compiler could merely segfault or do something even worse.

This series of statements

char *buf = 0;
buf = "";

declare buf as a char * and first set it to NULL. Then the second
statement sets buf to point to the start of an empty string, which is
simply a single null character. It is equivalent to this code:

char nullc = '\0'
char *buf = 0;
buf = &nullc;

with the caveat that the storage pointed to by the example above is
modifiable while the one preceding it is not. That's because string
literals are not, (or should not be), modifiable in C. Another
functionally equivalent code is:

char *buf = NULL;
buf = malloc(1 * sizeof *buf);
/* check malloc return */
*buf = 0;

So, in summary assigning a zero value to a pointer in an initialisation
is very different from assigning to it after deferencing it.

Can you understand the difference between these?

1. char *buf = 0;

2. char *buf;
buf = NULL;

3. char *buf;
char c = '\0';
buf = &c;

4. char *buf = NULL;
buf = "";
 
S

santosh

arnuld wrote:

BTW, I used %d, %lu, %s but what is %p ?

Conversion specifier to print a pointer value in a implementation
defined format. The corresponding argument should be cast to a void *
value for maximum portability.

The scanf family of functions also recognise %p and the corresponding
argument should be the address of a void *. The input must be in the
same format that printf outputs for a %p invocation.
 
N

Nick Keighley

If a well prepared and correct answer is found in the FAQ, wouldn't it
be a nice place to point people?
Brian posts here to be helpful. On those occasions when something is
not contained in the FAQ, he will post pertinant information regarding
the issue at hand.
Pretty much all usenet groups have FAQs and it is simple common
courtesy to read them before posting.

I am sorry but I know what a FAQ is. But one can point nearly all people
to the FAQ. Nicholas [...]

I prefer Nick to Nicholas.
[...] was abrupt I thought in his "have you bothered to
read the faq" comment.

I didn't intend to be abrupt but succinct. Note you have misquoted
me. What I actually wrote was:
no! NULL can be defined as ((void*)0) (note the zero at the end).
Have you read the comp.lang.c FAQ?

what you said I wrote borders on misrepresentation.
I corrected a (possible) misconception and then pointed him
at the FAQ. I did this because I believe NULL, 0, nil etc.
are confusing and the FAQ explains them well. Ben *may*
not have read these excellent explanations so I directed him
to them. What I understand of the issue is from reading the
FAQ. Why would I reproduce (badly) what has already been
done by a smarter person than myself (the FAQ writer)?

It was just my opinions that this is not the
right answer. One can always nicely refer people to it, but people can
not always find what they need if they dont know what the problem
is. Just my 2c of course. I think it is rude and you may of course think
otherwise. I didnt see Brian posting too much help only telling people
off so sorry if I was wrong

well rudeness is (partly) in the eye of the beholder.
 
S

santosh

Nick said:
user923005 said:
On Apr 29, 11:38 am, Eligiusz
Eligiusz Narutowicz wrote:
Most of answers are in the FAQ, but I dont know why someone
answers so. Why have a newsgroup if the people to help are
asking this?
What is the reason for having a newsgroup Frequently Asked
Question list?
I think that is very obvious. I don't know your point? So you will
only point people to the FAQ?
If a well prepared and correct answer is found in the FAQ, wouldn't
it be a nice place to point people?
Why do you post here then?
Brian posts here to be helpful. On those occasions when something
is not contained in the FAQ, he will post pertinant information
regarding the issue at hand.
Pretty much all usenet groups have FAQs and it is simple common
courtesy to read them before posting.

I am sorry but I know what a FAQ is. But one can point nearly all
people to the FAQ. Nicholas [...]

I prefer Nick to Nicholas.
[...] was abrupt I thought in his "have you bothered to
read the faq" comment.

I didn't intend to be abrupt but succinct. Note you have misquoted
me. What I actually wrote was:
no! NULL can be defined as ((void*)0) (note the zero at the end).
Have you read the comp.lang.c FAQ?

what you said I wrote borders on misrepresentation.
I corrected a (possible) misconception and then pointed him
at the FAQ. I did this because I believe NULL, 0, nil etc.
are confusing and the FAQ explains them well. Ben *may*
not have read these excellent explanations so I directed him
to them.

Note that you actually responded to arnuld. I don't think either Ben of
this group would need to consult the FAQ!

<snip>
 
B

Ben Bacarisse

Nick Keighley said:
I corrected a (possible) misconception and then pointed him
at the FAQ. I did this because I believe NULL, 0, nil etc.
are confusing and the FAQ explains them well. Ben *may*
not have read these excellent explanations so I directed him
to them.

I presume you mean Arnuld not Ben. Your reply was to him (and, yes, I
have read the FAQ).
 
A

arnuld

Obviously you wanted to do something else rather than invoke undefined
behavior here. Did you mean to use %p instead of %s? If so, it would
be a good to acquire the habit of casting the pointers to void* (even
though a char* would work without the cast).

I really meant %s because I am providing printf an array, whether empty or
full and you do see that its prints without any problem:


/home/arnuld/programs/C $ gcc -ansi -pedantic -Wall -Wextra test.c
/home/arnuld/programs/C $ ./a.out
(null)
(null)
/home/arnuld/programs/C $



BTW, I used %d, %lu, %s but what is %p ?
 

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,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top