|
From: Ioannis V. <no...@ho...> - 2002-11-19 20:27:25
|
> -----Original Message-----
> From: Ioannis Vranos [mailto:no...@ho...]
> Sent: Tuesday, November 19, 2002 10:21 PM
> To: 'dev...@li...'
> Subject: RE: [Dev-C++] A simple problem
>
>
> > -----Original Message-----
> > From: dev...@li...
> > [mailto:dev...@li...] On Behalf
> > Of Paul Ardeleanu
> > Sent: Tuesday, November 19, 2002 1:47 PM
> > To: dev...@li...
> > Subject: [Dev-C++] A simple problem
> >
> >
> > Can Anyone tell me why this code WORKS FINE in DevC++?
> > ANSI C says that it any Ansi compiler should give you an
> > error (see K&R
> > book).
> > Thank you very much!
> > Paul
> >
> > -----------------------------------------------------------
> > main ()
> > {
> > printf("hello, world
> > \n
> >
> >
> > ");
> > system("PAUSE");
> > }
>
>
> It is valid C90 code (and not C99).
>
> The main() thing is implicit int. In C90 you could do:
>
>
> const x=7;
>
> and it was equivallent to const int x=7;
>
>
> main() was equivallent to int main(). This is not the case in C99.
>
>
> Now both in C90 and C99 if you do not declare a function and
> you use it, a declaration of the type
>
>
> int whatever_you_use(); is assumed. The empty parenthesis is
> not equivallent to (void) as in C++. Empty parenthesis means
> that you want to skip argument checking.
>
>
> So when you use printf() without <stdio.h>, int printf(); is assumed.
I hadn't checked the entire code. The "broken" string literal is not
guaranteed to be portable (but GCC digests it). Also in your C90 code
you have to return 0; from main(), else you have "undefined behaviour".
K&R2 doesn't return 0; from main() which was the main murmur of C
programmers. Also the castings to malloc() are not needed (=better to be
avoided ) in C, although are used in K&R 2. K&R 2 casts malloc() because
they used a prototype C++ compiler to test the code (as you can read
somewhere in the preface).
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|