Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > What is strcmp supposed to return if one or both arguments passed to it are NULL ?

Reply
Thread Tools

What is strcmp supposed to return if one or both arguments passed to it are NULL ?

 
 
spibou@gmail.com
Guest
Posts: n/a
 
      07-13-2006
What is strcmp supposed to return if one or both arguments passed to it
are NULL ?

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      07-13-2006
said:

> What is strcmp supposed to return if one or both arguments passed to it
> are NULL ?


A demon.

Inspect your handkerchief - carefully.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      07-13-2006
wrote:

> What is strcmp supposed to return if one or both arguments passed to it
> are NULL ?


It isn't.

If either argument to strcmp is null, the behaviour is undefined.

So it may return -1, or 1, or 0, or 17, or 1829. It may generate some
kind of signal. It may exit, increment arbitrary memory, or call
some random one of your functions. Anything: the C standard places
no restrictions on strcmp if either argument is null; there is no
"supposed".

Typically, the behaviour is constrained by other standards and
mechanisms obeyed and performed by your implementation, so you'd
better hope that /they/ are working for you.

Are you willing to bet your nose on it?

--
Chris "one nostril at a time" Dollin
"I'm still here and I'm holding the answers" - Karnataka, /Love and Affection/

 
Reply With Quote
 
lovecreatesbeauty
Guest
Posts: n/a
 
      07-13-2006
wrote:
> What is strcmp supposed to return if one or both arguments passed to it
> are NULL ?


It may not be completed and crash midway, thereby having nothing
returned.

lovecreatesbeauty

 
Reply With Quote
 
goose
Guest
Posts: n/a
 
      07-13-2006
wrote:
> What is strcmp supposed to return if one or both arguments passed to it
> are NULL ?


Why don't you try it and let us know?

Or read a good C book?
Or read the FAQ for this group (posted everywhere)
Or read the standards document?

....

Or simply tell your instructor that you're
too lazy to be doing this course?

goose,
bad bad bad!!! I *really* should be more
mild on the newsgroups, but sometimes I just
cannot help myself.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      07-13-2006
"goose" <> writes:
> wrote:
>> What is strcmp supposed to return if one or both arguments passed to it
>> are NULL ?

>
> Why don't you try it and let us know?


Perhaps because trying it won't actually answer the question.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
goose
Guest
Posts: n/a
 
      07-13-2006

Keith Thompson wrote:
> "goose" <> writes:
> > wrote:
> >> What is strcmp supposed to return if one or both arguments passed to it
> >> are NULL ?

> >
> > Why don't you try it and let us know?

>
> Perhaps because trying it won't actually answer the question.
>


This is turning out to be an embarrassingly bad day for me

goose,

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      07-13-2006
"goose" <> writes:
> Keith Thompson wrote:
>> "goose" <> writes:
>> > wrote:
>> >> What is strcmp supposed to return if one or both arguments passed to it
>> >> are NULL ?
>> >
>> > Why don't you try it and let us know?

>>
>> Perhaps because trying it won't actually answer the question.

>
> This is turning out to be an embarrassingly bad day for me


We all have them.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
spibou@gmail.com
Guest
Posts: n/a
 
      07-13-2006

goose wrote:

> wrote:
> > What is strcmp supposed to return if one or both arguments passed to it
> > are NULL ?

> Or read the standards document?


I read the Standard. It didn't say.

 
Reply With Quote
 
Andrew Poelstra
Guest
Posts: n/a
 
      07-13-2006
On 2006-07-13, <> wrote:
>
> goose wrote:
>
>> wrote:
>> > What is strcmp supposed to return if one or both arguments passed to it
>> > are NULL ?

>> Or read the standards document?

>
> I read the Standard. It didn't say.
>


The Standard does say that if the Standard doesn't define something, it
is undefined.

Therefore, this is undefined.

--
Andrew Poelstra <http://www.wpsoftware.net/projects/>
To email me, use "apoelstra" at the above domain.
"You people hate mathematics." -- James Harris
 
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
Null pointer (NULL array pointer is passed) aneuryzma C++ 3 06-16-2008 05:48 AM
Why use "return (null);" instead of "return null;" ? Carl Java 21 08-24-2006 04:33 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
strcmp() question, 4 words, two strings, equal return value. Steven C Programming 9 12-29-2005 11:44 PM
NULL argument to strcmp Fred L. Kleinschmidt C Programming 15 12-17-2004 12:00 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57