NO

Author Topic: warning #2099: Missing type specifier; assuming 'int'.  (Read 5556 times)

Friso

  • Guest
warning #2099: Missing type specifier; assuming 'int'.
« on: April 23, 2012, 04:55:35 PM »
I get the following message:
Building Fahrenheit to Celsius 2.obj.
E:\C Practice\Fahrenheit to Celsius 2\Fahrenheit to Celsius 2.c(4): warning #2099: Missing type specifier; assuming 'int'.
Done.

But I don't see what is causing this.

The code is:

#include <stdio.h>

/* print Fahrenheit-Celsius table for fahr = 0, 20m ..., 300 */
main()
{
   float fahr, celsius;
   int lower, upper, step;

   lower = 0; /* lower limit of temperature table */
   upper = 300; /* upper limit*/
   step = 20; /* step size */

   fahr = lower;
   for (fahr = 0; fahr <= 300; fahr = fahr + step){
      celsius = (5.0/9.0) * (fahr-32.0);
      printf("%3.0f \t %6.1f\n", fahr, celsius);
   }
}


/* Any help will be much appreciated */

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: warning #2099: Missing type specifier; assuming 'int'.
« Reply #1 on: April 23, 2012, 05:05:19 PM »
I get the following message:
Building Fahrenheit to Celsius 2.obj.
E:\C Practice\Fahrenheit to Celsius 2\Fahrenheit to Celsius 2.c(4): warning #2099: Missing type specifier; assuming 'int'.
Done.

But I don't see what is causing this.
Look again, double click on the error message and at the same time, pay close attention to the second error message that you get right after the one you quoted... ;-)

And then write it properly as
Code: [Select]
int main (void) and magically, all the warnings are gone...  ;)

Ralf

Friso

  • Guest
Re: warning #2099: Missing type specifier; assuming 'int'.
« Reply #2 on: April 23, 2012, 05:54:55 PM »
Thank you very much. It works :)

Can you be so kind as to explain the syntax?
I can't find it in my book.

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: warning #2099: Missing type specifier; assuming 'int'.
« Reply #3 on: April 23, 2012, 08:19:41 PM »
Thank you very much. It works :)

Can you be so kind as to explain the syntax?
I can't find it in my book.
Well, the short version: You're book is so old that it refers to the old (original) syntax referred to as "K&R C" (named after the "inventors" Brian Kernighan and Dennis Ritchie(R.I.P.) ).
This style has been replaced for almost 30 years (first draft in '83) with what is referred to ANSI C (first ANSI Standard was C89, then C99 and now C11).
And that is what Pelle's C supports and hence the warning about the "assuming int" stuff.
It is better if you get used to using ANSI C syntax, as that is one way to eliminate possible mistakes by properly defining function types and arguments...

Ralf

CommonTater

  • Guest
Re: warning #2099: Missing type specifier; assuming 'int'.
« Reply #4 on: April 23, 2012, 09:28:37 PM »
Thank you very much. It works :)

Can you be so kind as to explain the syntax?
I can't find it in my book.

Further to bitbessier's excellent explaination, there are the requirements of the OS itself.

Windows expects certain things from programs and proscesses.  One of these is that each process returns a value to the operating system upon completion.  This value is normally an error report where 0 indicates success but it can be used for other purposes such as controlling batch files (IF ERRORLEVEL...) and returning process results to parent programs (eg.  GetExitCodeThread() )
 
This means that main() which is the first function in any console program has to return an integer value to the OS in order to be fully standards compliant. 
 
Moreover, as already explained every C function has a return value.  This can be void, any of the standard types (int, double, long, etc) or any user defined type (structs, etc.) Since every C function has a return value, with the exception of void, you are expected to actually return a value, thus the last statement in almost every function you write will be return.
 
Finally every C function accepts input values (called "Function Parameters") when a function is entered.  Like the return values these can be any valid type.  There are two exceptions to this, First is a function like ... main() ... which can accept any number of non-specified parameters and Second we have ...main(void)... which takes no parameters.
 
So taking all this together your minimum program skeleton is...
Code: [Select]
int main (void)
  {
    // your code goes here
 
    return 0;
  }

You should get into the habit of following this standard.
It's never too early to form good programming habits.
 
« Last Edit: April 23, 2012, 09:30:47 PM by CommonTater »