Re: caste Q
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 11/04/04
- Next message: Eric Sosman: "Re: check structure member at compile-time"
- Previous message: John Bode: "Re: Complex array definition"
- In reply to: Merrill & Michele: "caste Q"
- Next in thread: Eric Sosman: "Re: caste Q"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 4 Nov 2004 10:26:37 -0500 (EST)
On Thu, 4 Nov 2004, Merrill & Michele wrote:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(){
int main(void) is better style, IMNSHO. Provide prototypes for your
functions in C whenever possible. (In C++, I'd use the empty-parens
style, but C is not C++.)
> int rnd;
> long widernumber;
>
> srand(time));
Missing (NULL, and IIRC also a missing prototype for 'time'.
#include <time.h>
srand(time(0));
> rnd=rand();
> widernumber=(long)rnd;
Lose the spurious cast.
> printf=("wider number is %ld\n",widernumber)
Missing semicolon, bogus '=' sign after 'printf'.
> return 0
Missing semicolon.
> }
> Q1) Just so that I don't get ahead of myself, does the above code cast what
> is necessarily an integer as a long?
No, it's full of mistakes and outright errors. Learn to type correctly
before moving on to actual programming; it'll save you lots of grief in
the long run.
> Q2) What do the style people think about casts in general? MPJ
Casts are evil. There are maybe 3 or 4 places to use casts in C, and
none of them ought to appear in your average C program.
-Arthur
- Next message: Eric Sosman: "Re: check structure member at compile-time"
- Previous message: John Bode: "Re: Complex array definition"
- In reply to: Merrill & Michele: "caste Q"
- Next in thread: Eric Sosman: "Re: caste Q"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|