I thing it should generate a warning. but it doesn't. C51 COMPILER V8.16 Compiler settings: level=2
#include<something.h>
my_strange_global_variable = 1;
void main(void) { ...; }
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
'C' pretty much assumes that everything is an int unless specifically stated otherwise...
Yes, I know, but this is unprecise compiler behaviour not described in any standard. Declaration without a type identifier placed before main() dosn't generate warning and placed after main does generate a warning "undefined identifier"?
So let it be, I just accept it as it is.
this is unprecise compiler behaviour not described in any standard.
Actually, it's precisely described in every standard on the C programming language. This practice, sometimes referred to briefly as "implicit int", is likely to be disallowed in an upcoming revision of the C standard, but for now, it's valid C.
Which C standard do you mean?
He said, "every standard" - how many does that exclude?!
ISO 9899:1999 contains the following in the foreword:
Major changes from the previous edition include (item 5): [...] - remove implicit int
Well, every compiler I know acts differently on that code so I assume they represent full diversity of "standards". Ansi, C99, GNU C? Give me some links that proves there is one dominating "standard". I think that these are just propositions not rules and there doesn't exist fully standard compiler.
So how can you make your assertion that Keil should give a warning!
There are very few Warnings that are mandated by the standards - it is generally just a choice of the particular compiler to give a warning or not. Obviously, different compilers make different choices.
If you really want to catch (potential) problems like this, you should be using a static analyser; eg, Lint
"Give me some links that proves there is one dominating 'standard'"
The standards are the ISO standards (formerly ANSI); the standards supported by Keil are listed here:
http://www.keil.com/product/isoansi.asp
Yes, I know all of that. I just wanted to point out your evasive and selfprotective answers.
Your first answer should be "I have no idea why our compiler doesn't support every standard rule, take it as it is"
And thats's what I said. I just accept it.
When talking about standard definitions: Please define what you mean by "why our compiler".
You do realize that this is a forum for end users, and that Keil staff _may_ read some of the posts?
"...every compiler I know acts differently on that code..."
With that little amount of code, there would be very few possible ways for a compiler to treat it.
Can only assume you've only actually tried it on precious few compilers.
Thank you for reminding me that. I'm a little bit nervous because of hazy answers I get.
I'm a little bit nervous because of hazy answers I get.
The answers you got were razor sharp. You are the one the provided inadequate information!
How is that?
I assume they represent full diversity of "standards". Ansi, C99, GNU C?
There is only one actual C standard: ISO 9899. But from time to time, that standard is updated. The difference you observed was introduced in one such update, from ISO 9899:1990 (aka C90) to 9899:1999 (aka C99).
Implicit int was originally allowed by C's inventors, K&R, and kept by C90, but (to my surprise, now that I've actually looked it up), disallowed by C99.
Last I used it, Keil C51 only claimed support for C90, not C99. So there's nothing wrong with it allowing you to write code relying on implicit int.
I think that these are just propositions not rules and there doesn't exist fully standard compiler.
You think incorrectly on both counts. ISO C is very much a rule, and there do exist compilers that implement it completely.