Why do I get this warning in Pure C

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Zamuel_a
Atari God
Atari God
Posts: 1235
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Why do I get this warning in Pure C

Postby Zamuel_a » Tue Feb 04, 2014 9:39 am

Why does this code generete the warning "Call to function "test" with no prototype in main". It is no problem when I compile it on PC. I can't see that there should be anything missing.

Code: Select all

void test()
{
   
}

int main()
{
   test();

   return 0;
}
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 806
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Why do I get this warning in Pure C

Postby mfro » Tue Feb 04, 2014 12:03 pm

Zamuel_a wrote:Why does this code generete the warning "Call to function "test" with no prototype in main". It is no problem when I compile it on PC. I can't see that there should be anything missing.

Code: Select all

void test(void)
{
   
}

int main()
{
   test();

   return 0;
}


I didn't try myself, but I bet the warning will go away if you declare that test() doesn't take any parameters as shown above.

Zamuel_a
Atari God
Atari God
Posts: 1235
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: Why do I get this warning in Pure C

Postby Zamuel_a » Tue Feb 04, 2014 12:15 pm

No I tried that. I tried all kinds of combinations, (), (void)... move the order of them, declare void test(); above main, below main, inside main..... Always the same warning. The program itselfs runs, but I get ALOT of warnings since all function calls generate this.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe

joska
Hardware Guru
Hardware Guru
Posts: 4405
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Why do I get this warning in Pure C

Postby joska » Tue Feb 04, 2014 1:20 pm

The warning is correct. The prototype is missing, and the arguments are not specified in the implementation of the function. So while...

Code: Select all

void test() { }


...generates this warning,

Code: Select all

void test(void) { }


...doesn't. Tested with PureC 1.1.

In C, a declaration like "void test()" say that the function "test" takes an unspecified number of arguments. So you can leave out the arguments in the implementation of the function, and specify them in the prototype. Useful in some cases. You're missing the prototype :)

Code: Select all

void test(void); // Specify arguments here...

void test() // ...because you've left them out here :)
{
}


...is the correct way to do this if you don't want to specify the arguments in the implementation of the function.
Jo Even

VanillaMiNT - Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 806
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Why do I get this warning in Pure C

Postby mfro » Tue Feb 04, 2014 1:33 pm

Hmmm. I completely agree. But he said he'd tried that already....

Zamuel_a
Atari God
Atari God
Posts: 1235
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: Why do I get this warning in Pure C

Postby Zamuel_a » Tue Feb 04, 2014 2:06 pm

That solved the problem! Strange since I tried putting (void) in there but I must have done something wrong (or screwed up the files). It works for C functions, but what about assembler routines? I get the same warnings for an asm function even that the prototype in C is set to void test(void); Is there some way to define the asm function to be VOID to in a similar way?

EDIT:
Seems like if I add the definition void test(void); in my main C file (the asm routine is named test) it fix the problem. I had the definition in a .H file and I changed it to (void) here aswell but it's like it didn't take the update? It must reload it every time I compile the main C file?

EDIT again:
I renamed the .H file so I got an error (file not found), after that I changed the name back and NOW it worked! It seems like the .H file was cached or something so it didn't reload it, even if I had changed it. Is this correct or since I was running it from an emulator? (STEEM)
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12774
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Why do I get this warning in Pure C

Postby wongck » Tue Feb 04, 2014 2:35 pm

Under the SHELL Options of Pure C, there is a setting to cached H and objects files.
There's an option where you can clear them before running.
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

Zamuel_a
Atari God
Atari God
Posts: 1235
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: Why do I get this warning in Pure C

Postby Zamuel_a » Tue Feb 04, 2014 2:50 pm

wongck wrote:Under the SHELL Options of Pure C, there is a setting to cached H and objects files.
There's an option where you can clear them before running.


Ah thank you! That's why everything behaved so strange :wink:
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe

JeanMars
Captain Atari
Captain Atari
Posts: 172
Joined: Fri Apr 09, 2010 5:15 pm
Location: France
Contact:

Re: Why do I get this warning in Pure C

Postby JeanMars » Sun Mar 02, 2014 2:00 pm

Hi,

when you don't explicitely define parameters, int is assumed, so:
void test(){}
is recognized as void test(int){} by the compiler.

So, when you call test(), compiler actually expects test(some int), that's why you get this warning.
This warning can be ignored through compiler warning level, so your options should not be the same on PC and ST.

I don't think this has something to do with tthe cache.

Hope it helps,
Jean

joska
Hardware Guru
Hardware Guru
Posts: 4405
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Why do I get this warning in Pure C

Postby joska » Mon Mar 03, 2014 9:00 am

JeanMars wrote:when you don't explicitely define parameters, int is assumed, so:
void test(){}
is recognized as void test(int){} by the compiler.


Really? That's news to me. Where is this documented? AFAIK C doesn't make any assumptions about the number or type of parameters when the parameter list is empty. This is defined by the prototype.

JeanMars wrote:So, when you call test(), compiler actually expects test(some int), that's why you get this warning.


No, the warning was "no prototype", and - as explained above - refers to the fact that an empty parameter list is not a valid prototype in C.

Edit: here's a good explanation about the difference between a prototype and a parameter list.
Jo Even

VanillaMiNT - Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 4 guests