tag:blogger.com,1999:blog-5879050571098780501.post6685918113197939029..comments2023-07-29T17:37:04.170+05:30Comments on The Code Artist: What is NULL?Unknownnoreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5879050571098780501.post-54587778740883879942010-09-24T09:37:01.194+05:302010-09-24T09:37:01.194+05:30I guess it depends upon the compiler. I have seen ...I guess it depends upon the compiler. I have seen gcc compile the code with a simple warning "return with a value, in function returning void". This is because NULL is defined as void*(0).<br /><br />Semantically speaking, NULL and void are equivalent words. But syntactically speaking, void happens to indicate that there will be NO return statement.<br /><br />Any return statement in a function (even returning NULL) signifies that the function is non-void. Hence return(NULL) & void are contradictory.<br /><br />What it means to the programmer:<br />If your function returns some data in some cases and no data in other cases, then define it as a non-void function and use NULL when you have nothing to return.<br /><br />If your function NEVER has any data to return, then better define it as void.TheCodeArtisthttps://www.blogger.com/profile/11629092532561603507noreply@blogger.comtag:blogger.com,1999:blog-5879050571098780501.post-34357684651727907082010-09-21T20:40:10.823+05:302010-09-21T20:40:10.823+05:30Hi CVS, I had a question for you based on the defi...Hi CVS, I had a question for you based on the definition 3. What happens really when a function returns 0 (as in your case) while its return type is defined as void.<br /><br />Honestly NULL if really undefined or was nothing, then it should've been void in its truest sense. However, as you've rightly pointed out, in most use-cases, NULL is used with 0 as its definition (whether valid or not is another question).<br /><br />Now coming back, returning NULL from a function that shouldn't have returned anything... how valid is this?Anantha Keshavahttps://www.blogger.com/profile/04930388290481177282noreply@blogger.com