C Implicit declaration differs from internal function declaration - c

I'm having some trouble with C standard functions. As an example, I'm getting that error in the memcpy function, even passing the right arguments to it.
I've included a header as #include "header.h", and I've included , and so in the "header.h" file.
(I'm also getting this error with strcpy, strtok, and some other standard functions, all respective headers included in "header.h")
Can anyone please help me with this? I'm running out of time to deploy this work...
Thanks in advance

It seems it was some trouble within eclipse. I right clicked one of those functions, selected Source->Add includes and it solved the problem (but didn't added any header).
I hope this can be helpful for someone else

Since you have not posted your code I assume that you have not included the following lines of code, at the top of your file:
#include <string.h>
In case your are using a C++ compiler (i.e. g++) then:
#include <cstring>

Related

Why is it sometimes valid to write an include statement in a codeblock?

I amcoming from a python background, where the following is valid:
def f():
import someLibrary
someLibrary.libraryFunction()
So when I needed to debug C code, I wrote, in the middle of my function:
void f(int param)
{
int status;
/* other code */
#include <stdio.h>
printf("status: %d", status);
/* more code */
}
And it compiled and worked as I expected. Later it was pointed out to me that this shouldn't compile, since the C pre-processor literally replaces the #include~ statement with the contents ofstdio.h`.
So why was this valid code?
it was pointed out to me that this shouldn't compile, since the C pre-processor literally replaces the #include statement with the contents ofstdio.h.
The logic on that doesn't make sense. Just because the pre-processor inserts the text from the stdio.h file doesn't mean it should not compile. If there's nothing in that file that would result in a compile error, then it will compile just fine.
Furthermore, headers usually have a multiple inclusion guard in them. So if they were included already previously, any further attempts to include it have no effect. In this case, if <stdio.h> was already included previously in the file (directly or indirectly), the #include will have no effect.
With that being said, don't do that though. In C, standard headers are not supposed to be included while inside a function scope.
Yeah, C and Python are pretty different in this respect.
It is correct that the preprocessor replaces the #include directive with the contents of the included file prior to compilation.
Whether it leads to a compilation error or not depends entirely on the contents of the included file. Standard headers like stdio.h don't contain any executable statements - they only contain things like typdefs, function declarations, other macros, etc. They also usually have some kind of #include guards in place that prevent them from being loaded more than once per translation unit (that is, if you #include a file that includes stdio.h, and then #include <stdio.h> directly in the same source file, the contents of stdio.h will only be loaded once).
Theoretically, there's no problem with including stdio.h at random points in the code, but it can lead to problems. In this case all of stdio.h's contents will only be visible to the body of f - not a problem if only f needs to use anything in stdio.h, but otherwise it will lead to headaches.
Standard headers are best included at the beginning of the source file.

cvSaveImage was not declared in this scope?

My code worked perfectly for months until today. Its in C++
#include <iostream>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
using namespace std;
int main()
{
IplImage* img = cvLoadImage("C:/Users/Amadeus/Documents/H1/cat.png");
int result=cvSaveImage("C:/Users/Amadeus/Documents/H1/cat.png",img); <----- Problem
return 0;
}
It keeps saying "cvSaveImage was not declared in this scope". Files that would compile perfectly before all say it now. I don't understand why it worked for many months and today it says it wasn't declared. I even opened files that I knew worked for sure and even those didn't. It's like the header files are corrupt or something? What do you think?
Obviously, something changed in your system. I assume you don't know what exactly. The good point to start finding it out is to view your file after preprocessing is done. See for example this question on how to do this. Most probably you are pointing wrong or corrupted cv.h file for some reason.
By the way, why aren't you using modern C++ OpenCV functions imread and imwrite? They are in all ways better than their old C ancestors.

Minix - System call not correctly calling function?

I need to create a system call in Minix for a homework assignment. I've gotten most of the set up finished, but for some reason the function that the system call is actually calling isn't being found correctly. (Pardon any bad wording choices, I'm not sure the best words to explain this).
I've created a mylib.h in /usr/include (and /usr/src/include), with the following code:
#include <lib.h>
#include <unistd.h>
#include <stdio.h>
int mycall(){
message m;
return (_syscall(PM_PROC_NR, MYCALL, &m));
}
I also added mylib.h to the appropriate Makefile.
I've defined MYCALL in /usr/src/include/minix/callnr.h, and I've added do_mycall to the corresponding slot in /usr/src/servers/pm/table.h.
I've added int do_mycall(void); to /usr/src/servers/pm/proto.h, and I added a simple function declaration in misc.c.
int do_mycall(void){
printf("I've been called");
return 0;
}
I've also tried placing it in it's own .c file, which I added to the Makefile in that directory.
I performed make in /usr/src/servers/pm/ and /usr/src/include, and make includes in /usr/src/releasetools.
However, when I call mycall(), and catch the return value, it's -1.
I've added some prints, and I can tell that the function in mylib.h is being called, and MYCALL is correctly defined as the index in table.h, and table.h should have the do_mycall line correctly in place (though I don't really know how to test that it's there upon execution). So, all I can tell is that in _syscall, do_mycall isn't correctly mapping to it's function.
I tried replacing the prototype in photo.h with just the code in misc.c (so the prototype would be missing), but nothing happened differently, and make didn't complain.
Can anyone help me figure out what's causing this, or how I can narrow down where the disconnect is here?
If anyone knows where _syscall is defined, that might help, since I could maybe add some prints in it to figure out how far it's getting.
I was unable to find a specific cause, but after exhausting all options I could find, the issue appears to have been with my virtual machine. I repeated everything I did to set up the system call on VMware Player, instead of VirtualBox, and everything worked fine.

Warning: assignment makes pointer from integer without a cast undefined

I realise there are a lot of questions related to this issue but I couldn't make head nor tale from the ones I read through.
I'm trying to start learning C for the Amiga and decided to have a try following this tutorial:
http://www.pcguru.plus.com/tutorial/amiga_c.html
On reaching this point, I'm already running into noob problems:
#include <proto/intuition.h>
#include <intuition/screens.h>
#include <proto/dos.h>
#include <stdio.h>
int main(void) {
struct Screen *myScreen;
if (myScreen = LockPubScreen(NULL)) {
printf("Public Screen locked.\n");
Delay(100);
UnlockPubScreen(NULL, myScreen);
printf("Public Screen unlocked.\n");
}
return 0;
}
I'm using the GCC compiler with the following command from the Shell:
gcc -o LockPubScreen LockPubScreen.c
This returns the following:
Warning: assignment makes pointer from integer without a cast
undefined reference to 'LockPubScreen'
undefined reference to 'Delay'
undefined reference to 'UnlockPubScreen
Apart from 'HelloWorld' this is the first attempt at either C or programming the Amiga so I imagine I missing something obvious.
You probably need to include one or more of these additional files to get the prototype for the functions you're missing:
#include <intuition/gadgetclass.h>
#include <intuition/IntuitionBase.h>
#include <libraries/gadtools.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
Then, as NPE suggests, may may run into link errors if your compiler doesn't include the requisite library by default, and if you don't specify it.
If you had mentioned that you were trying to compile the program under AmigaOS 4.x, the answer would have been obvious. Library function calls in OS4 must either contain the library interface as well - IIntuition->LockPubScreen(), IDOS->Delay(), etc. - or you must #define __USE_INLINE__ at the beginning of the code.

error: identifier "sytem" is undefined

I have just started to learn C language and I'm just trying to write Hello World to get started but I get this error message. I'm sure the answer is obvious but can someone please tell me what I need to do? This is my code:
#include <stdio.h>
int main()
{
printf("Hello World ");
system("Pause");
return 0;
}
#include<stdlib.h>
Include this header file..
You need to add another header file:
#include <stdlib.h>
When you have an undefined call like this you can always throw "man 3 system" and you'll get something like this so you can see if you're missing a header file.
FYI, for your specific program, you may want to consider no using system("Pause") since it's system dependent. It would be better to pause with a break point (if you're using an IDE) or something more C standard like getchar()
You need to #include <stdlib.h>
If you aren't sure which header a standard function is defined in, its man page will tell you.
Insert
#include <stdlib.h> //in C
or
#include <cstdlib> //in C++
before your main() function.
Note that your IDE should refrain from closing your program. If it doesn't, change IDE.
You should include the following library.
#include <stdlib.h>
It's simple as that.
I hope you find this useful.
As the others said, you need to include an header; if you're running on Linux, you may install "manpages-dev" package, and then tape "man system" which will tell you what are the headers you need to use.

Resources