Click here to Skip to main content
15,885,998 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: Happy Birthday Dave! Pin
CPallini19-Dec-22 20:16
mveCPallini19-Dec-22 20:16 
GeneralRe: Happy Birthday Dave! Pin
Daniel Pfeffer19-Dec-22 21:15
professionalDaniel Pfeffer19-Dec-22 21:15 
GeneralRe: Happy Birthday Dave! Pin
theoldfool19-Dec-22 23:50
professionaltheoldfool19-Dec-22 23:50 
Generallearned a new trick to remove password from protected Excel sheet Pin
Southmountain19-Dec-22 17:43
Southmountain19-Dec-22 17:43 
GeneralRe: learned a new trick to remove password from protected Excel sheet PinPopular
Richard Deeming19-Dec-22 21:35
mveRichard Deeming19-Dec-22 21:35 
GeneralRe: learned a new trick to remove password from protected Excel sheet Pin
Southmountain20-Dec-22 2:59
Southmountain20-Dec-22 2:59 
Generalmalloc and calloc revisited - oh hum but pay attention when using them Pin
jmaida19-Dec-22 16:29
jmaida19-Dec-22 16:29 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
k505419-Dec-22 18:05
mvek505419-Dec-22 18:05 
jmaida wrote:
Lesson:
If one uses malloc and/or calloc then one should first test that memory size and unit size (in case of calloc) being requested are not zero, to guarantee the call produces a proper error condition (NULL).

I disagree. The lesson is that you should read and understand the C standard. Specifically:
Quote:
7.20.3 If the size of the space requested is zero, the behavior is implementation defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object.

Note that returning NULL for malloc(0) still requires you to know what the requested size was. malloc() and friends do return NULL if memory can not be assigned, in which case errno is set to ENOMEM. So if you get NULL back from malloc(), and you don't know the requested memory size, you need to check the value of errno. Furthermore, you also need to know that errno was not ENOMEM before you make the malloc() call, since successful library calls do not modify errno. As I understand it, calling malloc(0) is not an error, so will always succeed and therefore not change the value of errno.
Keep Calm and Carry On

GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
jmaida19-Dec-22 18:26
jmaida19-Dec-22 18:26 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
den2k8819-Dec-22 20:59
professionalden2k8819-Dec-22 20:59 
RantRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
Daniel Pfeffer19-Dec-22 21:13
professionalDaniel Pfeffer19-Dec-22 21:13 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
jmaida20-Dec-22 6:05
jmaida20-Dec-22 6:05 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
Bruno van Dooren20-Dec-22 11:04
mvaBruno van Dooren20-Dec-22 11:04 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
jmaida20-Dec-22 11:59
jmaida20-Dec-22 11:59 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
jschell20-Dec-22 13:56
jschell20-Dec-22 13:56 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
Bruno van Dooren20-Dec-22 19:45
mvaBruno van Dooren20-Dec-22 19:45 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
jschell29-Dec-22 11:15
jschell29-Dec-22 11:15 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
Bruno van Dooren30-Dec-22 8:08
mvaBruno van Dooren30-Dec-22 8:08 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
jschell2-Jan-23 13:17
jschell2-Jan-23 13:17 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
Bruno van Dooren2-Jan-23 13:27
mvaBruno van Dooren2-Jan-23 13:27 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
jmaida20-Dec-22 7:06
jmaida20-Dec-22 7:06 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
k505419-Dec-22 18:14
mvek505419-Dec-22 18:14 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
jmaida19-Dec-22 18:28
jmaida19-Dec-22 18:28 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
jschell20-Dec-22 13:57
jschell20-Dec-22 13:57 
GeneralRe: malloc and calloc revisited - oh hum but pay attention when using them Pin
jmaida20-Dec-22 14:04
jmaida20-Dec-22 14:04 

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.