>is it true that c compiler automatically picks a variable as an
>integer if we can't explicitly declare it at beginning of a program????
>
No. In C objects have to be declared before they are used.
I should amend that for global objects it's true that the type defaults to
int when it's not specifically mentioned. However it's extremely bad
practise.
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
>
I believe that this is a declaration of x. (It is a declaration
that does not explicitly give the type of x.)
I, in turn, believe that this was roughly what the OP was getting at - i.e.
implicit int.
<snip>
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
"jacob navia" <jacob@nospam.o rgschrieb im Newsbeitrag
news:47028ae8$0 $5103$ba4acef3@ news.orange.fr. ..
Richard Heathfield wrote:
>santosh said:
>>
>>aman wrote:
>>>
>>>is it true that c compiler automatically picks a variable as an
>>>integer if we can't explicitly declare it at beginning of a program????
>>No. In C objects have to be declared before they are used.
>
heathfield is using the wrong compiler!
>
d:\lcc\test>typ e th1.c
#include <stdio.h>
foo(x)
{
return printf("%d\n", x);
}
int main(void)
{
foo(42);
>
return 0;
}
>
d:\lcc\test>lc th1.c
Warning th1.c: 2 no type specified. Defaulting to int
Warning th1.c: 8 Missing prototype for 'foo'
0 errors, 2 warnings
Why? He basically got the same warnings as you got. (When compiling, not
when linking, no surprise there)
Hmm, actually he got 3 warnings, your compiler produced 2
>>
>I believe that this is a declaration of x. (It is a declaration
>that does not explicitly give the type of x.)
>
I, in turn, believe that this was roughly what the OP was getting at - i.e.
implicit int.
I can see that the OP's article could be interpreted that way.
It wasn't my interpretation.
--
"The fact that there is a holy war doesn't mean that one of the sides
doesn't suck - usually both do..."
--Alexander Viro
>>aman wrote:
>>>
>>>is it true that c compiler automatically picks a variable as an
>>>integer if we can't explicitly declare it at beginning of a program????
>>No. In C objects have to be declared before they are used.
"jacob navia" <jacob@nospam.o rgschrieb im Newsbeitrag
news:47028ae8$0 $5103$ba4acef3@ news.orange.fr. ..
>Richard Heathfield wrote:
>>santosh said:
>>>
>>>aman wrote:
>>>>
>>>>is it true that c compiler automatically picks a variable as an
>>>>integer if we can't explicitly declare it at beginning of a program????
>>>No. In C objects have to be declared before they are used.
>>True in C99, but who's got that?
>>>
>>rjh@linux:~/scratchcat foo.c
>>#include <stdio.h>
>>foo(x)
>>{
>> return printf("%d\n", x);
>>}
>>int main(void)
>>{
>> foo(42);
>>>
>> return 0;
>>}
>> me@here:~/scratchmake
>>gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith
>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
>> -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
>> -Wno-conversion -ffloat-store -O2 -g -pg -c -o foo.o foo.c
>>foo.c:3: warning: return-type defaults to `int'
>>foo.c:3: warning: function declaration isn't a prototype
>>foo.c: In function `foo':
>>foo.c:3: warning: type of `x' defaults to `int'
>>gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith
>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
>> -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
>> -Wno-conversion -ffloat-store -O2 -g -pg -o foo foo.o -lm
>>me@here:~/scratch./foo
>>42
>>me@here:~/scratch>
>heathfield is using the wrong compiler!
>>
>d:\lcc\test>ty pe th1.c
>#include <stdio.h>
>foo(x)
>{
> return printf("%d\n", x);
>}
>int main(void)
>{
> foo(42);
>>
> return 0;
>}
>>
>d:\lcc\test> lc th1.c
>Warning th1.c: 2 no type specified. Defaulting to int
>Warning th1.c: 8 Missing prototype for 'foo'
>0 errors, 2 warnings
Why? He basically got the same warnings as you got. (When compiling, not
when linking, no surprise there)
Hmm, actually he got 3 warnings, your compiler produced 2
>
Bye, Jojo
>
>
Sorry Joachim, I just did not see the warnings between all that
linking stuff.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
"jacob navia" <jacob@nospam.o rgschrieb im Newsbeitrag
news:47028dfd$0 $27377$ba4acef3 @news.orange.fr ...
Joachim Schmitz wrote:
>"jacob navia" <jacob@nospam.o rgschrieb im Newsbeitrag
>news:47028ae8$ 0$5103$ba4acef3 @news.orange.fr ...
>>Richard Heathfield wrote:
>>>santosh said:
>>>>
>>>>aman wrote:
>>>>>
>>>>>is it true that c compiler automatically picks a variable as an
>>>>>integer if we can't explicitly declare it at beginning of a
>>>>>program??? ?
>>>>No. In C objects have to be declared before they are used.
>>>True in C99, but who's got that?
>>>>
>>>rjh@linux: ~/scratchcat foo.c
>>>#include <stdio.h>
>>>foo(x)
>>>{
>>> return printf("%d\n", x);
>>>}
>>>int main(void)
>>>{
>>> foo(42);
>>>>
>>> return 0;
>>>}
>>> me@here:~/scratchmake
>>>gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith
>>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
>>> -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
>>> -Wno-conversion -ffloat-store -O2 -g -pg -c -o foo.o foo.c
>>>foo.c:3: warning: return-type defaults to `int'
>>>foo.c:3: warning: function declaration isn't a prototype
>>>foo.c: In function `foo':
>>>foo.c:3: warning: type of `x' defaults to `int'
>>>gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith
>>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
>>> -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
>>> -Wno-conversion -ffloat-store -O2 -g -pg -o foo foo.o -lm
>>>me@here:~/scratch./foo
>>>42
>>>me@here:~/scratch>
>>heathfield is using the wrong compiler!
>>>
>>d:\lcc\test>t ype th1.c
>>#include <stdio.h>
>>foo(x)
>>{
>> return printf("%d\n", x);
>>}
>>int main(void)
>>{
>> foo(42);
>>>
>> return 0;
>>}
>>>
>>d:\lcc\test>l c th1.c
>>Warning th1.c: 2 no type specified. Defaulting to int
>>Warning th1.c: 8 Missing prototype for 'foo'
>>0 errors, 2 warnings
>Why? He basically got the same warnings as you got. (When compiling, not
>when linking, no surprise there)
>Hmm, actually he got 3 warnings, your compiler produced 2
>>
>Bye, Jojo
>
Sorry Joachim, I just did not see the warnings between all that
linking stuff.
>I believe that this is a declaration of x. (It is a declaration
>that does not explicitly give the type of x.)
>
I, in turn, believe that this was roughly what the OP was getting at - i.e.
implicit int.
The OP should note that there are ways of defining a variable that avoid
explicitly providing a type. E.g.
{
auto i;
}
C99 has removed implicit int from the language, so I believe the above
is not valid C99.
--
Flash Gordon
>>is it true that c compiler automatically picks a variable as an
>>integer if we can't explicitly declare it at beginning of a program????
>>
>No. In C objects have to be declared before they are used.
>
I should amend that for global objects it's true that the type defaults to
int when it's not specifically mentioned. However it's extremely bad
practise.
There isn't really a distinction between "global" and other objects.
C90 allows implicit int in a number of contexts. For example:
static x; /* x is int by default */
auto y; /* y is int by default; allowed only inside a function */
register z; /* z is int by default; allowed only inside a function */
Generally an object (variable) declaration requires *either* a storage
class *or* a type.
But declaring a variable without specifying its type is considered
poor style, and the newer C99 standard forbids it.
You can do it, but you shouldn't.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Comment