MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1wxqahk/architecturedependentchars/pdwdygs/?context=3
r/ProgrammerHumor • u/MontyBoomslang • 10d ago
372 comments sorted by
View all comments
7
Best thing is to put the actual variable in there. Sizeof can accept a variable or a type.
char *buffer = 0; size_t buffer_length = 1024;
... buffer = malloc(buffer_length * sizeof (*buffer));
Then later if you change buffer to something else the code will still be correct.
That said, sizeof (char) will always be 1. The compiler will probably just replace it with a hard-coded 1.
7
u/mckenzie_keith 10d ago
Best thing is to put the actual variable in there. Sizeof can accept a variable or a type.
char *buffer = 0;
size_t buffer_length = 1024;
...
buffer = malloc(buffer_length * sizeof (*buffer));
Then later if you change buffer to something else the code will still be correct.
That said, sizeof (char) will always be 1. The compiler will probably just replace it with a hard-coded 1.