473,804 Members | 3,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Jul 13 '06 #1
14 2209
sp****@gmail.co m 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)
Jul 13 '06 #2
sp****@gmail.co m 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/

Jul 13 '06 #3
sp****@gmail.co m 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.

lovecreatesbeau ty

Jul 13 '06 #4
sp****@gmail.co m 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.

Jul 13 '06 #5
"goose" <ru**@webmail.c o.zawrites:
sp****@gmail.co m 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_Keit h) ks***@mib.org <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.
Jul 13 '06 #6

Keith Thompson wrote:
"goose" <ru**@webmail.c o.zawrites:
sp****@gmail.co m 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,

Jul 13 '06 #7
"goose" <ru**@webmail.c o.zawrites:
Keith Thompson wrote:
>"goose" <ru**@webmail.c o.zawrites:
sp****@gmail.co m 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_Keit h) ks***@mib.org <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.
Jul 13 '06 #8

goose wrote:
sp****@gmail.co m 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.

Jul 13 '06 #9
On 2006-07-13, sp****@gmail.co m <sp****@gmail.c omwrote:
>
goose wrote:
>sp****@gmail.co m 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
Jul 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2267
by: Nobody | last post by:
Lets say I have a class that is only available if a specific DLL (a.dll) is present. I can't link to that DLL through lib files or my app will fail on any machine that doesn't have a.dll. So I do LoadLibrary()'s and keep function pointers in my wrapper class... Which is a better style? DWORD CClass::SomeFunc() { if (m_pfn != NULL)
53
8308
by: Allan Bruce | last post by:
Hi there, I am reading a file into a char array, and I want to find if a string exists in a given line. I cant use strcmp since the line ends with '\n' and not '\0'. Is there a similar function that will do this, or will I have to write my own? Thanks Allan
140
7922
by: Oliver Brausch | last post by:
Hello, have you ever heard about this MS-visual c compiler bug? look at the small prog: static int x=0; int bit32() { return ++x; }
21
2255
by: tyler_durden | last post by:
hi there peeps... like I say in the topic, I need to do an e-mail program in C language, and has to be made until the 3th of january..the problem is I'm having some problems with it. I was wondering if someone had a program like this..it has to send e-mails, read e-mails from a .txt file and show them in the screen with the subject, date, etc... can someone please help me out? thanks
16
2003
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't see how the return value comes to play here. Ex
15
13086
by: XZ | last post by:
Hi everyone, this is really confusing to me: #include <stdio.h> main(int argc, char **argv) { printf("argv = %f\n",(double)atof(argv)); printf("argv = %d\n\n",atoi(argv)); } $ a.out a argv = 97.000000
12
2385
by: shya | last post by:
hi there! I just wrote a function that reverse a string. It seems all ok to me, but the program goes on segmentation fault on *s = *t_str. Here's the code: #include <stdio.h> #include <stdlib.h> void reverse(char *s) {
21
13854
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered by Sets. - ICollection cannot decide containment - IList promises indexability by the natural numbers, which is not achievable (since i hash elements, not sort them). - IDictionary is definatly not setlike. Although I can, of course, define...
47
3031
by: fishpond | last post by:
One way I've seen strcmp(char *s1, char *s2) implemented is: return immediately if s1==s2 (equality of pointers); otherwise do the usual thing of searching through the memory at s1 and s2. Of course the reason for doing this is to save time in case equal pointers are passed to strcmp. But it seems to me that this could create an inconsistency in the degenerate case when s1 points to memory that is not null-terminated, i.e. by some freak...
0
10586
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6856
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.