Click here to Skip to main content
15,887,683 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
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 
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 
Again.

GCC is behaving according to the C Standard, which specifies that malloc(0) or calloc(0, x) return either NULL, or a unique pointer. This is implementation defined behaviour - the implementation must specify what behaviour it supports.

Your code is not checking the size of the block referenced by sz, sizeof(*sz). It is checking the size of the pointer, sizeof(sz). You are apparently running on a system with 64-bit pointers.

If malloc(x) or calloc(y, x) return a non-NULL pointer, you are guaranteed that it points to a memory area of at least x or x * y chars, respectively. In order to discover the exact area, you will need to call an implementation-specific API; the C Standard does not define an API to return the actual size of an allocated memory area.

Note that even if the result of malloc(0) or calloc(0, x) is a unique pointer, that pointer cannot be portably dereferenced, as it is guaranteed to reference only a zero-sized memory area.
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 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 
GeneralRe: With all these style questions, Pin
Nelek12-Dec-22 11:37
protectorNelek12-Dec-22 11:37 
GeneralRe: With all these style questions, Pin
Greg Utas12-Dec-22 13:21
professionalGreg Utas12-Dec-22 13:21 

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.