Page 1 of 2

Stressful (for me) Problem with Bran's Tutorial

Posted: Wed Nov 07, 2007 6:41 pm
by nightfire8199
I have followed Bran's Tutorial on osdever.net to the dot on the i's (figuratively). but when it comes time to compile, gcc (in Linux) has some UBER-problem with everything I do. the main compile error output (for main.c only) is that main() is not an int or something to that regard. and that puts is not correct. Below is the actual output:

Code: Select all

main.c:50: warning: return type of ‘main’ is not ‘int’
main.c: In function ‘main’:
main.c:63: warning: pointer targets in passing argument 1 of ‘puts’ differ in signedness
I'm not sure at all what this means, but I can tell that it isn't going to spit out a main.o, Help?

Posted: Wed Nov 07, 2007 7:30 pm
by Brynet-Inc
Be considerate of people using dark themes... use

Code: Select all

 blocks..  :roll:

Posted: Wed Nov 07, 2007 8:30 pm
by nightfire8199
sorry, didnt think of that , now its changed. any Ideas?

Posted: Wed Nov 07, 2007 8:34 pm
by Alboin
They're just warnings. main.c should still compile.

Re: Stressful (for me) Problem with Bran's Tutorial

Posted: Thu Nov 08, 2007 1:00 am
by Candy
nightfire8199 wrote:I have followed Bran's Tutorial on osdever.net to the dot on the i's (figuratively). but when it comes time to compile, gcc (in Linux) has some UBER-problem with everything I do. the main compile error output (for main.c only) is that main() is not an int or something to that regard. and that puts is not correct. Below is the actual output:

Code: Select all

main.c:50: warning: return type of ‘main’ is not ‘int’
main.c: In function ‘main’:
main.c:63: warning: pointer targets in passing argument 1 of ‘puts’ differ in signedness
I'm not sure at all what this means, but I can tell that it isn't going to spit out a main.o, Help?
They mean that Bran hasn't been adhering to the C standard (at least, not the one you're trying to use to compile it). You're probably compiling it as C99, whereas it is written in C89 or older.

The first means that you have

Code: Select all

void main()
or

Code: Select all

main()
but the standard requires you to say

Code: Select all

int main()
because it will always have an integer return value.

The second means that you pass a parameter to puts that isn't of the right type, where the old compiler didn't complain (most likely since you could call undeclared functions). New compilers do complain because it's just plain wrong.

Re: Stressful (for me) Problem with Bran's Tutorial

Posted: Thu Nov 08, 2007 7:15 am
by jal
nightfire8199 wrote:I'm not sure at all what this means, but I can tell that it isn't going to spit out a main.o, Help?
If you are not sure what that means, and also if you think it prevents creating a main.o, you do not have the required knowledge to make an OS. Really.


JAL

Posted: Thu Nov 08, 2007 7:18 am
by Craze Frog
main() has a special meaning in C. Just rename your function k_main() or something and the warning will go away.

Re: Stressful (for me) Problem with Bran's Tutorial

Posted: Thu Nov 08, 2007 7:11 pm
by crazygray
Candy wrote:
nightfire8199 wrote:I have followed Bran's Tutorial on osdever.net to the dot on the i's (figuratively). but when it comes time to compile, gcc (in Linux) has some UBER-problem with everything I do. the main compile error output (for main.c only) is that main() is not an int or something to that regard. and that puts is not correct. Below is the actual output:

Code: Select all

main.c:50: warning: return type of ‘main’ is not ‘int’
main.c: In function ‘main’:
main.c:63: warning: pointer targets in passing argument 1 of ‘puts’ differ in signedness
I'm not sure at all what this means, but I can tell that it isn't going to spit out a main.o, Help?
They mean that Bran hasn't been adhering to the C standard (at least, not the one you're trying to use to compile it). You're probably compiling it as C99, whereas it is written in C89 or older.

The first means that you have

Code: Select all

void main()
or

Code: Select all

main()
but the standard requires you to say

Code: Select all

int main()
because it will always have an integer return value.

The second means that you pass a parameter to puts that isn't of the right type, where the old compiler didn't complain (most likely since you could call undeclared functions). New compilers do complain because it's just plain wrong.

Posted: Fri Nov 09, 2007 3:38 am
by 01000101
why did the above poster just post quotes? lol.

Posted: Fri Nov 09, 2007 5:33 am
by AJ
I have noticed this quite a bit recently - people posting a full quote despite answering the post above. If you are picking out bits and answering them individually, fair enough, but there's no need to quote the entire topic history in each answer :roll:

Cheers,
Adam

Posted: Sat Nov 10, 2007 3:11 pm
by jal
AJ wrote:but there's no need to quote the entire topic history in each answer
Indeed, just the bits answered is fine enough.


JAL

Posted: Mon Nov 12, 2007 7:54 am
by AndrewAPrice
Craze Frog wrote:main() has a special meaning in C. Just rename your function k_main() or something and the warning will go away.
No it doesn't. main() is no different to any other function. It is usually the first C/C++ function called in your code, but you can easily edit your assembly stub to change that.

Posted: Mon Nov 12, 2007 8:08 am
by JamesM
MessiahAndrw wrote:
Craze Frog wrote:main() has a special meaning in C. Just rename your function k_main() or something and the warning will go away.
No it doesn't. main() is no different to any other function. It is usually the first C/C++ function called in your code, but you can easily edit your assembly stub to change that.
Not correct. In implementation main() is no different however it is defined to have a certain form by both the POSIX and C99 standards. Same with printf.

Won't cause an error but will cause warnings.

Posted: Mon Nov 12, 2007 8:10 am
by Craze Frog
MessiahAndrw wrote:
Craze Frog wrote:main() has a special meaning in C. Just rename your function k_main() or something and the warning will go away.
No it doesn't. main() is no different to any other function. It is usually the first C/C++ function called in your code, but you can easily edit your assembly stub to change that.
No, main has a special meaning. It means, "this is where I want the program execution to start". Just read the C99 standard, section 5.1.2.2.1. The same standard also prohibits any function named main to have any other return type than int. Which is the reason for the warning in GCC.

Edit: JamesM got there before me, but unfortunately he isn't completely correct either.
In implementation main() is no different...
Source code:

Code: Select all

int crudebox() {
    __asm__("#CODE START 2");
    __asm__("#CODE END 2");
    return 0;
}

int main() {
    __asm__("#CODE START");
    __asm__("#CODE END");
    return 0;
}
Asm generated by gcc 3.4.4 for cygwin:

Code: Select all

...
_crudebox:
	pushl	%ebp
	movl	%esp, %ebp
/APP
	#CODE START 2
	#CODE END 2
/NO_APP
	popl	%ebp
	xorl	%eax, %eax
	ret
...
_main:
	pushl	%ebp
	movl	$16, %eax
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	call	__alloca
	call	___main
/APP
	#CODE START
	#CODE END
/NO_APP
	leave
	xorl	%eax, %eax
	ret
I agree that it shouldn't be like that, the stack probing should be done in another function that calls main, but someone decided to do it like that.

Posted: Mon Nov 12, 2007 8:20 am
by AndrewAPrice
JamesM wrote:
MessiahAndrw wrote:
Craze Frog wrote:main() has a special meaning in C. Just rename your function k_main() or something and the warning will go away.
No it doesn't. main() is no different to any other function. It is usually the first C/C++ function called in your code, but you can easily edit your assembly stub to change that.
Not correct. In implementation main() is no different however it is defined to have a certain form by both the POSIX and C99 standards. Same with printf.

Won't cause an error but will cause warnings.
Aww man :( I just wanted to correct Crazy Frog on something to make him feel dumb after he posted this (and after reading that, click the link to his blog in his profile for more Linux and C bashing).