Cute little trick for gcc or clang users: (run valgrind on it afterwards)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
void raii_char_free(char **);
#define raii_char_pointer char * __attribute__ ((__cleanup__(raii_char_free)))
void raii_char_free(char **p) {
free(*p);
}
int main (void) {
raii_char_pointer ptr = strdup("abcdefg");
printf("%s\n", ptr);
return 0;
}
@ivesen you trying to say that size doesn't matter?
@ivesen that's either really big or really small
@ExistentialCrisis sure, what's the prob?
use https://godbolt.org/ to test code on multiple compilers without having to have them installed locally
If you are programming in C consider adding c++ guards around your file scope variables and prototypes, and use the c++ compiler. You will find additional errors and warnings the c compilers alone won't find. Also, compile with both gcc and clang and use as many others as well as static analysis tools as you can. cppcheck can be your friend. valgrind can be your best friend.
@ExistentialCrisis Hello
@CyclopsCaveman If I ever meet you I will have hard enough time remembering your name. When we meet again, I will have forgotten your name, and absent a name tag I will ask it again. As for your pronouns, I will mostly be using "you" as I will rarely have reason to speak of you in 3rd person. And if I do speak of you in 3rd person, it would be by your name. I just don't find pgp's useful.
@kiilas wow, that is a very generous offer. I have a feeling I may have to take you up on it.
The green faerie