Sujet : Re: So You Think You Can Const?
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.lang.cDate : 13. Jan 2025, 01:46:29
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vm1np5$1fn6n$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 1/7/2025 11:32 AM, Julio Di Egidio wrote:
Hi everybody,
I am back to programming in C after many years:
indeed I have forgotten so many things, including
how much I love this language. :)
From reading this thread I take it you would prefer this style:
______________________
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
int main()
{
int* a = malloc(sizeof(*a));
if (! a)
{
// shit happens! ;^o
return EXIT_FAILURE;
}
// okay...
*a = 42;
printf("a = %p\n", (void*)a);
printf("*a = %d\n", *a);
uintptr_t x = (uintptr_t)a;
free(a);
printf("x = %" PRIxPTR " was just freed! do not deref\n", x);
return 0;
}
______________________
over this thing:
______________________
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
int main()
{
int* a = malloc(sizeof(*a));
if (a)
{
*a = 42;
printf("a = %p\n", (void*)a);
printf("*a = %d\n", *a);
uintptr_t x = (uintptr_t)a;
free(a);
printf("x = %" PRIxPTR " was just freed! do not deref\n", x);
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
______________________
? Am I on the right track with your form? Say you were reviewing by code. Bad, or really bad!
;^)
[...]