I have a Question about memory usage for C.

This is a discussion on I have a Question about memory usage for C. within the C Programming forums, part of the General Programming Boards category; To oomakoo I gave up trying to explain because I felt like a broken record and didn't want to plague ...

  1. #31
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    To oomakoo I gave up trying to explain because I felt like a broken record and didn't want to plague people with a spam war.
    What have you explained? The only place I could find any sort of explaination was (I assume you were unregistered) -

    In addition, omitting the cast does, as Quzah said, allow the compiler to be more accurate in what errors/warnings it provides you.
    Exactly what errors/warnings is the compiler going to give (with no cast) when assigning from a void pointer? The only way to enable the compiler to do any sort of checking would be to cast.
    zen

  2. #32
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Leave out the needed header, and your program will compile without error if you've typecast everything.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #33
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    I get the same warning messages with or without the cast (implicit declaration).
    zen

  4. #34
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I get the same warning messages with or without the cast (implicit declaration).
    Hm... You may be right. I'm not at a compiler now. Shrug. Oh well. I can't recall the error, or how to do it, (maybe it's just a warning?) but I know there's one you can get with casts. I've done it in the past--i think. It's been a long time. I generally never cast malloc except on accident. Just the way I do it.

    Quzah.
    Last edited by quzah; 12-24-2001 at 04:06 PM.
    Hope is the first step on the road to disappointment.

  5. #35
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Testing on a few different compilers produces different results, so this may be the warning you are thinking of. However, the only compliant C99 compiler that I know of gives errors if stdlib.h isn't included regardless of whether you cast or not. I suppose it's up to the compiler writers what warnings to include on a pre-C99 compiler.

    You could argue that assigning the result of malloc to a pointer that you thought was of a different type could result in a harder to find bug than forgetting to include stdlib.h. If you're careful though, neither would be a problem.
    zen

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer memory question
    By Edo in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2009, 03:36 AM
  2. Memory allocation question
    By dakarn in forum C Programming
    Replies: 11
    Last Post: 12-01-2008, 11:41 PM
  3. Another Question...memory allocation
    By quickclick330 in forum C Programming
    Replies: 4
    Last Post: 12-12-2007, 04:25 PM
  4. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  5. [C] Trouble with memory usage
    By BianConiglio in forum Windows Programming
    Replies: 1
    Last Post: 09-28-2004, 09:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21