C warnings?

Programming, for all ages and all languages.
Post Reply
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

C warnings?

Post by computertrick »

Here is my code

Code: Select all

#include "stdio.h"
#include "cpu.h"
#include "memory.h"
void cpu_start()
{
	for (;;)
	{
		int test = 5;
		exec_8(test);
		StepIP(1);
	}

}



void exec_8(int a)
{

}
I get these warnings
root@bt:~/Desktop/x86Emu# bash build.sh
cpu.c:17: warning: conflicting types for ‘exec_8’
cpu.c:9: note: previous implicit declaration of ‘exec_8’ was here
x86Emu compiled!
Can someone tell me why this is happening

Thanks
1100110100010011
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: C warnings?

Post by qw »

Look for implicit function declaration.
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Re: C warnings?

Post by mathematician »

I would hazard a guess that it is complaining because you call exec_8 before you define it. So it guesses the return type to be an int, and later discovers it to be void. Either use a prototype, or place exec_8 before the function which calls it.
The continuous image of a connected set is connected.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: C warnings?

Post by computertrick »

mathematician wrote:I would hazard a guess that it is complaining because you call exec_8 before you define it. So it guesses the return type to be an int, and later discovers it to be void. Either use a prototype, or place exec_8 before the function which calls it.
Putting

Code: Select all

exec(unsigned char op);
worked like a charm!

Thanks
1100110100010011
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: C warnings?

Post by Love4Boobies »

Other than the fact that C only does one pass and has implicit declarations, there is no such thing as stdio.h (i.e., the fact that you included it with quotes worked by mistake but can break elsewhere), only <stdio.h> (as it needn't be implemented as an actual file), as is the case for all standard library headers.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: C warnings?

Post by computertrick »

Love4Boobies wrote:Other than the fact that C only does one pass and has implicit declarations, there is no such thing as stdio.h (i.e., the fact that you included it with quotes worked by mistake but can break elsewhere), only <stdio.h> (as it needn't be implemented as an actual file), as is the case for all standard library headers.

So what your saying is for standard libraries in the operating system use

Code: Select all

#include <library>
instead of

Code: Select all

#include "library"
1100110100010011
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: C warnings?

Post by Kazinsal »

That is basic C and I think you need to step back and actually learn the language before attempting to write something complex in it.
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: C warnings?

Post by bwat »

computertrick wrote: So what your saying is for standard libraries in the operating system use

Code: Select all

#include <library>
instead of

Code: Select all

#include "library"
You can probably use #include "library" if you want but you have to understand your implementation to make sure. File inclusion is not determined by the language, but by the implementation. Even the difference between the two methods of file inclusion in ANSI C depends upon something that is described as "deliberately implementation-dependent" in section A12.4 of the second edition of Kernighan & Ritchie. If you don't have that book then you maybe want to get your hands on it.
Post Reply