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
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 
GeneralRe: Style question Pin
jmaida14-Dec-22 11:37
jmaida14-Dec-22 11:37 
I agree. One last test. Using calloc and malloc

I tried both malloc and calloc and got same results.
The calls do not return NULL even if specifying ZERO bytes.
I am using Codeblocks IDE with latest GCC and have C std-17 2017 standard flag set

int ZERO = 0;

char *sz;
char *sx;

printf("Hello world!\n");

sz = (char*)malloc(ZERO);
// sz = (char*)calloc(ZERO, (int)sizeof(sz));
if( sz == NULL ) printf( "returned NULL allocated zero bytes\n");
else printf( "NULL not returned from malloc, allocated 8 bytes\n" );
sx = strchr("",1);


printf( "Sizeof char_sz %d bytes value %p\n", (int)sizeof(sz), sz );
printf( "Sizeof char_sx %d bytes value %p\n", (int)sizeof(sx), sx );
free( sz );
printf( "Sizeof char_sz %d bytes value %p after free\n", (int)sizeof(sz), sz );

Results:

Hello world!
NULL not returned from malloc, allocated 8 bytes
Sizeof char_sz 8 bytes value 0000000000b213f0
Sizeof char_sx 8 bytes value 0000000000000000
Sizeof char_sz 8 bytes value 0000000000b213f0 after free
"A little time, a little trouble, your better day"
Badfinger

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 
GeneralRe: With all these style questions, Pin
Nelek12-Dec-22 11:37
protectorNelek12-Dec-22 11:37 

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.