On Sun, 09 Mar 2008 14:57:38 -0600, Falcon Kirtaran
<> wrote in comp.lang.c:
> Bill Cunningham wrote:
> > I am stumped on this one. I tried two methods and something just doesn't
> > seem right. I'll try my new syle.
> >
> > #include <stdio.h>
> > #include <stdlib.h>
> >
> > main() {
> > srand(2000); /*seed unsigned */
> > printf("%u",rand());
> > }
> >
> > Now I get a number much larger than 2000. Also when I also try RAND_MAX with
> > srand from time to time.
> >
> > With main I was always told int was the default type and didn't need to be
> > declared. Main() has always worked. I hope this code is much more readable.
> >
> > Bill
[snip]
> As for your main(), I wasn't actually aware that such code was legal C.
Wherever did you get that idea? That code was perfectly legal in C up
until the 1999 update to the C language standard.
> My guess is that it is actually void main(), because you never return
Now you're getting silly. Prior to C99, everyplace where it was legal
to define or declare something without an explicit type, it was
implicitly typed as int. Never as void.
main()
....prior to C99, was exactly identical to:
int main()
....and is illegal under C99 and later versions, as all declarators
must explicitly declare a type.
> a value from it, so the exit status of your program is most likely
> undefined. It is a good idea, particularly in UNIX, to declare it int,
> and return 0 at the end (unless the program failed).
This is correct under any version of the C standard. If a program
"falls off the end" of main() without returning a value, the exit
status returned to the environment is undefined.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html