Always cast malloc

Discussion in 'C Programming' started by E. Robert Tisdale, Oct 20, 2003.

  1. Always write:

    double* x = (double*)malloc(n*sizeof(double));

    instead of


    double* x = malloc(n*sizeof(*x));
     
    E. Robert Tisdale, Oct 20, 2003
    #1
    1. Advertising

  2. E. Robert Tisdale

    Artie Gold Guest

    E. Robert Tisdale wrote:
    > Always write:
    >
    > double* x = (double*)malloc(n*sizeof(double));
    >
    > instead of
    >
    >
    > double* x = malloc(n*sizeof(*x));
    >


    Always refrigerate tomatoes. Makes just about as much sense.

    --aG

    --
    Artie Gold -- Austin, Texas
    Oh, for the good old days of regular old SPAM.
     
    Artie Gold, Oct 21, 2003
    #2
    1. Advertising

  3. E. Robert Tisdale

    Jalapeno Guest

    [Tisdale is Osama bin Laden] was Re: Always cast malloc

    In article <>,
    "E. Robert Tisdale" <> wrote:

    > Always write:
    >
    > double* x = (double*)malloc(n*sizeof(double));
    >
    > instead of
    >
    >
    > double* x = malloc(n*sizeof(*x));
    >


    This is secret code. I'm telling Ashcroft on you.
     
    Jalapeno, Oct 21, 2003
    #3
  4. E. Robert Tisdale

    Mike Wahler Guest

    "E. Robert Tisdale" <> wrote in message
    news:...
    > Always write:
    >
    > double* x = (double*)malloc(n*sizeof(double));
    >
    > instead of
    >
    >
    > double* x = malloc(n*sizeof(*x));\


    Slow day today, Robert?

    -Mike
     
    Mike Wahler, Oct 21, 2003
    #4
  5. "E. Robert Tisdale" <> writes:
    > Always write:
    >
    > double* x = (double*)malloc(n*sizeof(double));
    >
    > instead of
    >
    > double* x = malloc(n*sizeof(*x));


    Is this a deliberate troll? If so, please stop wasting our time and
    confusing the newbies. If you really have a point, please explain it.

    A quick response just in case you're serious about this:

    You're wrong.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
     
    Keith Thompson, Oct 21, 2003
    #5
  6. Mike Wahler wrote:

    > E. Robert Tisdale wrote:
    >
    >>Always write:
    >>
    >> double* x = (double*)malloc(n*sizeof(double));
    >>
    >>instead of
    >>
    >> double* x = malloc(n*sizeof(*x));

    >
    > Slow day today, Robert?


    I dug this up out of another thread: why still use C?
    Sidney Cadot and Mark McIntyre are having a slow day as well.
     
    E. Robert Tisdale, Oct 21, 2003
    #6
  7. E. Robert Tisdale

    Jack Klein Guest

    On Mon, 20 Oct 2003 15:54:42 -0700, "E. Robert Tisdale"
    <> wrote in comp.lang.c:

    > Always write:
    >
    > double* x = (double*)malloc(n*sizeof(double));
    >
    > instead of
    >
    >
    > double* x = malloc(n*sizeof(*x));


    To quote the disheveled E. Robert Tisdale:

    > This is an obvious troll. Please ignore it.


    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
     
    Jack Klein, Oct 21, 2003
    #7
  8. E. Robert Tisdale

    Mike Wahler Guest

    "E. Robert Tisdale" <> wrote in message
    news:...
    > Mike Wahler wrote:
    >
    > > E. Robert Tisdale wrote:
    > >
    > >>Always write:
    > >>
    > >> double* x = (double*)malloc(n*sizeof(double));
    > >>
    > >>instead of
    > >>
    > >> double* x = malloc(n*sizeof(*x));

    > >
    > > Slow day today, Robert?

    >
    > I dug this up out of another thread: why still use C?


    And presented it here without context.

    > Sidney Cadot and Mark McIntyre are having a slow day as well.


    So what's your motivation for posting a couple lines from
    another thread without context?

    I find this quite ironic from one who is very quick
    to cry 'troll' around here.

    -Mike
     
    Mike Wahler, Oct 21, 2003
    #8
  9. E. Robert Tisdale wrote:

    > Always write:
    >
    > double* x = (double*)malloc(n*sizeof(double));
    >
    > instead of
    >
    >
    > double* x = malloc(n*sizeof(*x));



    The latter is clearly superior, for reasons which have been presented ad
    nauseam in this newsgroup for years. That Tisdale recommends the former,
    then, comes as no surprise. His advice may safely be ignored.


    --
    Richard Heathfield :
    "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    K&R answers, C books, etc: http://users.powernet.co.uk/eton
     
    Richard Heathfield, Oct 21, 2003
    #9
  10. Always write:

    double *x = malloc(n * sizeof *x);

    instead of


    double* x = malloc(n*sizeof(*x));
     
    Irrwahn Grausewitz, Oct 21, 2003
    #10
  11. E. Robert Tisdale

    Dan Pop Guest

    In <> "E. Robert Tisdale" <> writes:

    >Always write:
    >
    > double* x = (double*)malloc(n*sizeof(double));
    >
    >instead of
    >
    >
    > double* x = malloc(n*sizeof(*x));


    _____________________
    /| /| | |
    ||__|| | Please do not |
    / O O\__ | feed the |
    / \ | Trolls |
    / \ \|_____________________|
    / _ \ \ ||
    / |\____\ \ ||
    / | | | |\____/ ||
    / \|_|_|/ | _||
    / / \ |____| ||
    / | | | --|
    | | | |____ --|
    * _ | |_|_|_| | \-/
    *-- _--\ _ \ | ||
    / _ \\ | / `'
    * / \_ /- | | |
    * ___ c_c_c_C/ \C_c_c_c____________

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Oct 21, 2003
    #11
  12. E. Robert Tisdale

    The Clap Guest

    > In <> "E. Robert Tisdale"
    > <> writes:
    >
    >>Always write:
    >>
    >> double* x = (double*)malloc(n*sizeof(double));
    >>
    >>instead of
    >>
    >>
    >> double* x = malloc(n*sizeof(*x));

    >
    > _____________________
    > /| /| | |
    > ||__|| | Please do not |
    > / O O\__ | feed the |
    > / \ | Trolls |
    > / \ \|_____________________|
    > / _ \ \ ||
    > / |\____\ \ ||
    > / | | | |\____/ ||
    > / \|_|_|/ | _||
    > / / \ |____| ||
    > / | | | --|
    > | | | |____ --|
    > * _ | |_|_|_| | \-/
    > *-- _--\ _ \ | ||
    > / _ \\ | / `'
    > * / \_ /- | | |
    > * ___ c_c_c_C/ \C_c_c_c____________
    >
    > Dan


    http://goatse.cx/

    * g o a t s e x * g o a t s e x * g o a t s e x *
    g g
    o / \ \ / \ o
    a| | \ | | a
    t| `. | | : t
    s` | | \| | s
    e \ | / / \\\ --__ \\ : e
    x \ \/ _--~~ ~--__| \ | x
    * \ \_-~ ~-_\ | *
    g \_ \ _.--------.______\| | g
    o \ \______// _ ___ _ (_(__> \ | o
    a \ . C ___) ______ (_(____> | / a
    t /\ | C ____)/ Dan \ (_____> |_/ t
    s / /\| C_____) Pop | (___> / \ s
    e | ( _C_____)\______/ // _/ / \ e
    x | \ |__ \\_________// (__/ | x
    * | \ \____) `---- --' | *
    g | \_ ___\ /_ _/ | g
    o | / | | \ | o
    a | | / \ \ | a
    t | / / | | \ |t
    s | / / \__/\___/ | |s
    e | / / | | | |e
    x | | | | | |x
    * g o a t s e x * g o a t s e x * g o a t e x *

    http://goatse.cx/
     
    The Clap, Oct 21, 2003
    #12
  13. E. Robert Tisdale

    CBFalconer Guest

    Richard Heathfield wrote:
    >

    .... snip ...
    >
    > The latter is clearly superior, for reasons which have been presented ad
    > nauseam in this newsgroup for years. That Tisdale recommends the former,
    > then, comes as no surprise. His advice may safely be ignored.


    I think that is a syntax error. It should be "His advice may not
    be taken in safety". A Karnaugh map of the available actions may
    make it clearer.

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
     
    CBFalconer, Oct 21, 2003
    #13
  14. E. Robert Tisdale

    Sidney Cadot Guest

    Hi Mark,

    > "E. Robert Tisdale" <> wrote in message
    > news:...
    >
    >>Always write:
    >>
    >>double* x = (double*)malloc(n*sizeof(double));
    >>
    >>instead of
    >>
    >>
    >>double* x = malloc(n*sizeof(*x));\

    >
    >
    > Slow day today, Robert?


    How about we put an end to our mutual barrage of repetitive statements?
    Hells bells, I'll even leave the final round to you. I'm sure we can
    find another topic later on to slug it out :)

    Best regards, Sidney
     
    Sidney Cadot, Oct 21, 2003
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MSG

    to cast or not to cast malloc ?

    MSG, Feb 6, 2004, in forum: C Programming
    Replies:
    38
    Views:
    1,096
    Dan Pop
    Feb 10, 2004
  2. EvilRix
    Replies:
    8
    Views:
    661
    Martin Dickopp
    Feb 14, 2004
  3. John
    Replies:
    13
    Views:
    716
  4. ravi
    Replies:
    0
    Views:
    461
  5. Pavel
    Replies:
    7
    Views:
    546
    Pavel
    Sep 19, 2010
Loading...

Share This Page