Stressful (for me) Problem with Bran's Tutorial

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
nightfire8199
Posts: 8
Joined: Wed Nov 07, 2007 6:33 pm

Stressful (for me) Problem with Bran's Tutorial

Post 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?
Last edited by nightfire8199 on Wed Nov 07, 2007 8:32 pm, edited 3 times in total.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Be considerate of people using dark themes... use

Code: Select all

 blocks..  :roll:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
nightfire8199
Posts: 8
Joined: Wed Nov 07, 2007 6:33 pm

Post by nightfire8199 »

sorry, didnt think of that , now its changed. any Ideas?
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

They're just warnings. main.c should still compile.
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

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

Post 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.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

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

Post 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
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post by Craze Frog »

main() has a special meaning in C. Just rename your function k_main() or something and the warning will go away.
User avatar
crazygray
Member
Member
Posts: 73
Joined: Sat Nov 03, 2007 10:17 am
Location: Toky,Japan

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

Post 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.
Imagine if a creature came from a 4 dimensional world, would he think you to be flat?
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

why did the above poster just post quotes? lol.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post 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
User avatar
AndrewAPrice
Member
Member
Posts: 2309
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post 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.
My OS is Perception.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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.
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post 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.
User avatar
AndrewAPrice
Member
Member
Posts: 2309
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post 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).
My OS is Perception.
Post Reply