Click here to Skip to main content
15,887,676 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Style question Pin
jmaida12-Dec-22 16:22
jmaida12-Dec-22 16:22 
GeneralRe: Style question Pin
honey the codewitch12-Dec-22 20:33
mvahoney the codewitch12-Dec-22 20:33 
GeneralRe: Style question Pin
k505413-Dec-22 3:19
mvek505413-Dec-22 3:19 
GeneralRe: Style question Pin
honey the codewitch13-Dec-22 4:09
mvahoney the codewitch13-Dec-22 4:09 
GeneralRe: Style question Pin
jmaida13-Dec-22 10:17
jmaida13-Dec-22 10:17 
GeneralRe: Style question Pin
Daniel Pfeffer13-Dec-22 10:44
professionalDaniel Pfeffer13-Dec-22 10:44 
GeneralRe: Style question Pin
jmaida13-Dec-22 15:42
jmaida13-Dec-22 15:42 
GeneralRe: Style question Pin
Daniel Pfeffer13-Dec-22 22:16
professionalDaniel Pfeffer13-Dec-22 22:16 
The result of malloc(0) is implementation defined. Your compiler apparently allocates a minimal block of memory for each malloc(0), allowing you to call free() on the block. Note that the block may not be portably dereferenced, as its size is 0.

The other option in the C Standard is to return NULL. This also allows free() to be called on the "block", because free(NULL) is specifically allowed in the Standard. The result also cannot be dereferenced (dereferencing NULL is undefined behaviour).
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.

GeneralRe: Style question Pin
jmaida14-Dec-22 11:37
jmaida14-Dec-22 11:37 
GeneralRe: Style question Pin
Daniel Pfeffer14-Dec-22 11:52
professionalDaniel Pfeffer14-Dec-22 11:52 
GeneralRe: Style question Pin
jmaida14-Dec-22 12:08
jmaida14-Dec-22 12:08 
GeneralRe: Style question Pin
trønderen14-Dec-22 11:55
trønderen14-Dec-22 11:55 
GeneralRe: Style question Pin
jmaida14-Dec-22 12:10
jmaida14-Dec-22 12:10 
GeneralRe: Style question Pin
jmaida15-Dec-22 16:10
jmaida15-Dec-22 16:10 
GeneralRe: Style question Pin
Mircea Neacsu12-Dec-22 16:55
Mircea Neacsu12-Dec-22 16:55 
GeneralRe: Style question Pin
jmaida12-Dec-22 18:48
jmaida12-Dec-22 18:48 
GeneralRe: Style question Pin
k505413-Dec-22 3:07
mvek505413-Dec-22 3:07 
GeneralRe: Style question Pin
Mircea Neacsu13-Dec-22 9:13
Mircea Neacsu13-Dec-22 9:13 
GeneralRe: Style question Pin
jmaida13-Dec-22 10:30
jmaida13-Dec-22 10:30 
GeneralRe: Style question Pin
honey the codewitch12-Dec-22 20:33
mvahoney the codewitch12-Dec-22 20:33 
GeneralRe: Style question Pin
11917640 Member 12-Dec-22 23:29
11917640 Member 12-Dec-22 23:29 
GeneralWith all these style questions, Pin
MarkTJohnson12-Dec-22 8:52
professionalMarkTJohnson12-Dec-22 8:52 
GeneralRe: With all these style questions, Pin
0x01AA12-Dec-22 9:16
mve0x01AA12-Dec-22 9:16 
JokeRe: With all these style questions, Pin
raddevus12-Dec-22 10:59
mvaraddevus12-Dec-22 10:59 
GeneralRe: With all these style questions, Pin
OriginalGriff12-Dec-22 11:25
mveOriginalGriff12-Dec-22 11:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.