Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
why is casting malloc a bad thing?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="magesh, post: 1698501"] I completely agree with the fact that proper header files should be included, I would be amazed a proper C file that never calls a function from stdlib, so normal programmers include them, if they give attention to warnings from the compiler or else this thread is not meant for them. Thats what I think, but I agree with fact that unnecessary casts may fool the compiler and prevent from warning, if not properly used. declaration of p 1000 lines before. 1001: p= malloc(sizeof(*p)*10); or those who don't care of memory 1001: p= malloc(1024); could you tell me what type is p, while u are going through just this part of ur code. 1001: p= (int*)malloc(sizeof(int)*10); Thought it appears newbie ,I think this is more explicit! Reagrding code maintenance, the other solution p= malloc(sizeof(*p)*10); may be easy to change the type of p without changing the malloc line in ur code, after that?? the fact that the type of p has changed may have more impact on other lines where u use them, than those on one malloc statement!!! Yep thats what I expect too. Thanks for ur reply, regards, magesh [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
why is casting malloc a bad thing?
Top