Hacker News new | ask | show | jobs
by clarry 3460 days ago
> I would hope a practicing programmer would realize that sizeof is a keyword and evaluated at compile time

I must nitpick. sizeof may or may not be evaluated at compile time. It is not possible to always evaluate it at compile time (see VLAs). The standard even includes an example of this:

         #include <stddef.h>
         size_t fsize3(int n)
         {
               char b[n+3];                  // variable length array
               return sizeof b;              // execution time sizeof
         }

          int main()
          {
                size_t size;
                size = fsize3(10); // fsize3 returns 13
                return 0;
          }
1 comments

You are correct. I forgot about variable length arrays.