0

I tried running server.c outside the appliance on my mac and when compiling got the following message server.c:358:26: error: implicit declaration of function 'memmem' is invalid in C99 [-Werror,-Wimplicit-function-declaration] needle = memmem(haystack, size, "\r\n\r\n", 4); ^ server.c:358:26: note: did you mean 'memset'? /usr/include/string.h:74:7: note: 'memset' declared here void *memset(void *, int, size_t); ^ server.c:358:24: error: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Werror,-Wint-conversion] needle = memmem(haystack, size, "\r\n\r\n", 4); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ server.c:375:60: error: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Werror,-Wformat] if (dprintf(cfd, "Content-Length: %i\r\n", length) < 0) ~~ ^~~~~~ %zu server.c:426:60: error: format specifies type 'int' but the argument has type 'ssize_t' (aka 'long') [-Werror,-Wformat] if (dprintf(cfd, "Content-Length: %i\r\n", length) < 0) ~~ ^~~~~~ %zi server.c:727:15: error: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Werror,-Wint-conversion] ...needle = memmem(haystack, request + length - haystack, "\r\n\r\n", 4); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 errors generated.

I've installed all the libraries required for programming with C on my mac and why didn't the compiling worked?

1 Answer 1

0

From the look of it, it seems you may have omitted the function prototype for memmem.

error: implicit declaration of function 'memmem' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

Since a compiler reads source code from left to right top to bottom, this is just a cryptic way of saying "I've gone through your program and did not see anything related to the function you are calling."

The next line:

note: did you mean 'memset'?

Is just trying to be helpful by suggesting a function that the language knows up until this point.

The other four errors were generated from each of the arguments passed into the function. As it was stated in the prior weeks, you'll just need to fix the first error to fix all of the errors.

If you get any errors regarding this function after adding in the prototype for this function, you may have spelling issues.

Hope this helps.

3
  • I've got the same question as well! Can someone help us please. The functions memmem and memset are declared in the library <string.h> but the compiler recognize it as implicit declaration of function...? Why?
    – Jack Lee
    Commented Nov 23, 2016 at 12:16
  • Did you read my response? If you look at the man page for memmem it states that you need to include string.h inside of your source code. if you are trying to run this from within xcode, you may have problems, instead use clang in the terminal or copy and paste the code in a new terminal xcode project set to the C language.
    – Bob R.
    Commented Nov 25, 2016 at 20:38
  • I have read your response. Thank you very much. I have included string.h in my source code and used clang to compile (yes I am using a mac). But that didn't help solve the problem. Could you please help please?
    – Jack Lee
    Commented Nov 28, 2016 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .