Hacker News new | ask | show | jobs
by jasode 2103 days ago
>This depends on the compiler as well as the processor.

Yes. On x64 compilers targeting 64bit cpus, the following prints 8 instead of 4:

  #include <iostream>
  int main () {
      std::cout << sizeof(int*) << std::endl;
  }
2 comments

Posting C++ in a thread about C is odd. In C it's:

    #include <stdio.h>

    int main(void)
    {
      printf("%zu\n", sizeof (int *));
      return 0;
    }
There's a double-quote character missing.
Thanks. I suck at posting from my phone. Edited.
The article talks about the size of the pointee in memory though, not the size of the pointer.

An 'int' is usually 4 bytes wide when compiling for 64-bit ISAs (at least I haven't seen situations yet where this isn't the case, my experience is limited to x86 and ARM though). Modern C fixes this ambiguity with sized integer types (e.g. int32_t vs int64_t).

>The article talks about the size of the pointee in memory though, not the size of the pointer.

Yes, you're right about the article's text. When I read gp ChrisSD's comment in isolation where he quotes ">A pointer is a memory address" -- followed immediately by him quoting ">On current mainstream Intel processors, _it_ occupies four bytes of memory"

... I thought the "_it_" was referring to a "pointer" instead of plain "int". It didn't occur to me to that the actual article has extra text in between those 2 extracted quotes which drastically changes the assumption of what the pronoun "it" means. My mistake.