3 ms·
Well it's an operator, and algebra said all them are just functions... Just like `+` is a function Anyways not all those writing code have CS background
by _lce0 11y ago
Well it's an operator, and algebra said all them are just functions... Just like `+` is a function
Anyways not all those writing code have CS background
- masklinn 11y agoExcept sizeof is a compile-time operation, not runtime. If sizeof were a function, int *foo = malloc(sizeof(*foo)); would make no sense.
- rdc12 11y agoSo in practice it works more like a C Macro then a C function? Edit, except it doesn't treat arguments the same, so no.
- cygx 11y agoIt's neither: sizeof belongs in its own category of unary compile-time(-ish) operators, whose only other member is _Alignof. If you're so inclined, you might add _Generic and _Pragma to that mix as well, but they aren't really a close fit.
- barrkel 11y agoCompile-time functions are a thing. Not in C, but in other languages, including C++. This all comes down to what you think "function" means. If you're living in a C bubble, of course sizeof isn't a function. If you have a wider mapping (!) for the word, then it is a kind of function.
- mcguire 11y agoIf you think everything called a "function", in every context, is the same thing, you are going to have a very bad day.
- userbinator 11y agoIn C99, sizeof is compile-time only if VLAs are not involved. In C89, sizeof is always compile-time.
- weland 11y agoExcept algebra said that about algebraic functions and operators. I know a CS major who insisted in pointing out the same thing. He was extremely surprised when dragons hatched from his eggs instead of the chickens he expected. It was a really heated event. He barely escaped -- and then ranted for several weeks how they were really just eggs and couldn't explain what happened.