ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#include <string.h>
int main ()
{
stricmp ("anisha", "kaul");
return 0;
}
Code:
anisha@linux-uitj:~> gcc junk.c -Wall -Wextra
junk.c: In function ‘main’:
junk.c:5: warning: implicit declaration of function ‘stricmp’
/tmp/ccUhL95d.o: In function `main':
junk.c:(.text+0x14): undefined reference to `stricmp'
collect2: ld returned 1 exit status
The link you gave us pointed to a QNX man page. QNX is not Linux; you have shown us that QNX offers a function, stricmp(), which is not part of the POSIX standard.
#include <string.h>
int main ()
{
stricmp ("anisha", "kaul");
return 0;
}
Code:
anisha@linux-uitj:~> gcc junk.c -Wall -Wextra
junk.c: In function ‘main’:
junk.c:5: warning: implicit declaration of function ‘stricmp’
/tmp/ccUhL95d.o: In function `main':
junk.c:(.text+0x14): undefined reference to `stricmp'
collect2: ld returned 1 exit status
If it were nt inside string.h, it should hv been a compiler error you were getting instead of linker error.
So you can look whether the definition is inside some Compiler directive[macros]
If it were nt inside string.h, it should hv been a compiler error
He got compiler warning first.
Quote:
junk.c:5: warning: implicit declaration of function ‘stricmp’
This means that function has not been declared ealier (even in string.h) and compiler did it automagically - but this was not been intention of programmer.
If it were nt inside string.h, it should hv been a compiler error you were getting instead of linker error.
So you can look whether the definition is inside some Compiler directive[macros]
Okay, look at the following code, I ve added another function: junk.c
Code:
#include <string.h>
int main ()
{
stricmp ("sad", "sdsa");
unknown ();
return 0;
}
Output:
Code:
anisha@linux-uitj:~> gcc junk.c -Wall -Wextra
junk.c: In function ‘main’:
junk.c:5: warning: implicit declaration of function ‘stricmp’
junk.c:6: warning: implicit declaration of function ‘unknown’
/tmp/cc8TuWnE.o: In function `main':
junk.c:(.text+0x14): undefined reference to `stricmp'
junk.c:(.text+0x1e): undefined reference to `unknown'
collect2: ld returned 1 exit status
The link you gave us pointed to a QNX man page. QNX is not Linux; you have shown us that QNX offers a function, stricmp(), which is not part of the POSIX standard.
Thanks for pointing that out!
Now I looked up Goooooo to find out this:
Quote:
QNX is a commercial Unix-like real-time operating system, aimed primarily at the embedded systems market.
Secondly, I looked up /usr/src/linux-2.6.31.5-0.1/include/linux/string.h
I saw there a function named: strnicmp, which is not much different from stricmp!
Is there any link which contains all Posix standard functions?
Last edited by Aquarius_Girl; 12-12-2010 at 10:32 PM.
Reason: made a new post for the edits
Here strnicmp is missing in that link but it is present in string.h in my computer with OpenSuse 11.2 with the following declaration: extern int strnicmp(const char *, const char *, __kernel_size_t);
Code:
#include <string.h>
int main ()
{
strnicmp ("anisha", "kaul");
return 0;
}
Code:
anisha@linux-uitj:~> gcc junk.c -Wall -Wextra
junk.c: In function ‘main’:
junk.c:5: warning: implicit declaration of function ‘strnicmp’
/tmp/ccI5NoIs.o: In function `main':
junk.c:(.text+0x14): undefined reference to `strnicmp'
collect2: ld returned 1 exit status
Code:
anisha@linux-uitj:~> man strnicmp
STRNICMP(9) Basic C Library Functions STRNICMP(9)
NAME
strnicmp - Case insensitive, length-limited string comparison
SYNOPSIS
int strnicmp(const char * s1, const char * s2, size_t len);
ARGUMENTS
s1
One string
s2
The other string
len
the maximum number of characters to compare
COPYRIGHT
Kernel Hackers Manual 2.6.
Last edited by Aquarius_Girl; 12-12-2010 at 10:37 PM.
You could return to google and search for "standard POSIX functions". That yields two very useful links near the top of the search, to wikipedia articles entitled "POSIX" and "C POSIX library". Browse through both of those; the second one contains this very useful link.
it is present in string.h in my computer with OpenSuse 11.2[/I][/U] with the following declaration: extern int strnicmp(const char *, const char *, __kernel_size_t);
Hmmmm. "Present". You use that term. I do not think it means what you think it means. Is that line surrounded by any conditional compilation directives which end up excluding it?
Here's a test, if it's in fact your computer: Change that line in string.h so it says:
Code:
exxtern int strnicmp(const char *, const char *, __kernel_size_t);
That's right. Put an extra x in there. If your code still compiles, then this line was excluded by conditional compilation directives, so the compiler didn't care about that extra x. (Be sure to change it back, just because leaving a mess is not a good idea.)
Hmmmm. "Present". You use that term. I do not think it means what you think it means. Is that line surrounded by any conditional compilation directives which end up excluding it?
Thanks again for the useful link and comments! I don't know what has that monster to do with all this?? You write it most often, it is because the question was dumb?
I have attached the string.h and bolded the relevant text. I'll try out your way but why is the man page there then?
Here's your trouble. You're probably not including string.h, but rather strings.h. I'm glad you're posting its content; see this part?
Code:
/* We don't want strings.h stuff being used by user stuff by accident */
#ifndef __KERNEL__
#include <string.h>
#else
If in fact you're including strings.h, those lines in that file correct the error for you, and nothing else (see that else?) in the file will be accessible to you, including strnicmp.
Quote:
Originally Posted by anishakaul
why is the man page there then?
Excellent question. If you posted the entire man page, it omits a very important section: the CONFORMING TO section. Does your man page for strncasecmp have such a section? There's one in Debian's man page:
Code:
CONFORMING TO
4.4BSD, POSIX.1-2001.
Quote:
Originally Posted by anishakaul
I don't know what has that monster to do with all this??
Happy to enlighten you. First, read all about the Flying Spaghetti Monster here. I started invoking its name after another poster, in asking a question, began his question in the name of Allah. Someone else objected, and a moderator stepped in, saying that we shouldn't be "making religious statements" in our posts. The moderator locked the thread. I suspect there's a certain amount of unintentional bias here, because nobody seems to be disciplined because of including (Christian) Bible quotations in his signature. I raised the issue with the moderator, asking whether we were going to be consistent, and got no answer. So I'm using this greeting to establish a precedent. Maybe they'll discipline me with ten lashes with a wet piece of spaghetti or something. (The normal English idiom for ridiculously mild punishment would be "ten lashes with a wet noodle".) For more information, go here and here and here.
Sorry Anisha I second time mistake someone gender. There should be some kind of sex mark near the nick.
Quote:
Okay, look at the following code, I ve added another function: junk.c
Code:
#include <string.h>
int main ()
{
stricmp ("sad", "sdsa");
unknown ();
return 0;
}
Now whatdoyou say
I could say the same as ealier But I try to say that otherwise. In C every undeclared function, like unknown() and stricmp() is automaticaly declared during first occurrence by the compiler. It is declared but anywhere defined. So compiler generate a warning (implicit declaration of function) and linker an error (undefined reference to).
You can get better error handling if you use C++. It has more strict syntax. In your example it will generate compiler error just where is stricmp() that it wasn't anywhere declared.
Okay, look at the following code, I ve added another function: junk.c
Code:
#include <string.h>
int main ()
{
stricmp ("sad", "sdsa");
unknown ();
return 0;
}
Output:
Code:
anisha@linux-uitj:~> gcc junk.c -Wall -Wextra
junk.c: In function ‘main’:
junk.c:5: warning: implicit declaration of function ‘stricmp’
junk.c:6: warning: implicit declaration of function ‘unknown’
/tmp/cc8TuWnE.o: In function `main':
junk.c:(.text+0x14): undefined reference to `stricmp'
junk.c:(.text+0x1e): undefined reference to `unknown'
collect2: ld returned 1 exit status
Now whatdoyou say
I believe she was trying to correct me. Thank you anisha...Accepted. I did not pay much attention.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.