News for hackers. Stuff that matters.
Re:Everything you need to know about pointers in C (2010) by jasode on Tuesday September 15, 2020 @05:59AM (#24479531)
>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;
  }
Re:Everything you need to know about pointers in C (2010) by unwind on Tuesday September 15, 2020 @06:16AM (#24479611)
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;
    }
Re:Everything you need to know about pointers in C (2010) by MaxBarraclough on Tuesday September 15, 2020 @06:40AM (#24479711)
There's a double-quote character missing.
Re:Everything you need to know about pointers in C (2010) by unwind on Tuesday September 15, 2020 @10:20AM (#24481461)
Thanks. I suck at posting from my phone. Edited.
Re:Everything you need to know about pointers in C (2010) by flohofwoe on Tuesday September 15, 2020 @06:53AM (#24479789)
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).

Re:Everything you need to know about pointers in C (2010) by jasode on Tuesday September 15, 2020 @08:06AM (#24480250)
>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.