Everything you need to know about pointers in C (2010)
1–10 of 25 posts
Re: Everything you need to know about pointers in C (2010)
#2This is an amazingly wrong statement. In assembly you deal with memory addresses. Pointers in C are a much higher level abstraction.
> On current mainstream Intel processors, it occupies four bytes of memory (because an int is four bytes wide).
This depends on the compiler as well as the processor.
Re: Everything you need to know about pointers in C (2010)
#3> A pointer is a memory address. This is an amazingly wrong statement. In assembly you deal with memory addresses. Pointers in C are a much higher level abstraction. > On current mainstream Intel processors, it occupies four bytes of memory (because an int is four bytes wide). 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
int main () {
std::cout Re: Everything you need to know about pointers in C (2010)
#4> A pointer is a memory address. This is an amazingly wrong statement. In assembly you deal with memory addresses. Pointers in C are a much higher level abstraction. > On current mainstream Intel processors, it occupies four bytes of memory (because an int is four bytes wide). This depends on the compiler as well as the processor.
C11 6.5.3.2p3 “The unary & operator yields the address of its operand. If the operand has type ‘type’, the result has type ‘pointer to type’.”
I understand the intention to warn about the abstraction C introduces, but you’ve confused things.
Pointers and addresses are perfectly covered.
What you really want to bring is what the Standard calls the “C abstract machine”, for which the memory model can be surprising.
Re: Everything you need to know about pointers in C (2010)
#5No, void pointer arithmetic is not allowed by the C standard: https://stackoverflow.com/questions/3523145/pointer-arithmet...
Re: Everything you need to know about pointers in C (2010)
#6> A pointer is a memory address. This is an amazingly wrong statement. In assembly you deal with memory addresses. Pointers in C are a much higher level abstraction. > On current mainstream Intel processors, it occupies four bytes of memory (because an int is four bytes wide). This depends on the compiler as well as the processor.
>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 int main () { std::cout
#include
int main(void)
{
printf("%zu\n", sizeof (int *));
return 0;
}Re: Everything you need to know about pointers in C (2010)
#7> void pointers are incremented or decremented by 1 byte. No, void pointer arithmetic is not allowed by the C standard: https://stackoverflow.com/questions/3523145/pointer-arithmet...
Re: Everything you need to know about pointers in C (2010)
#8Re: Everything you need to know about pointers in C (2010)
#9Earlier quoted context omitted.
>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 int main () { std::cout
Posting C++ in a thread about C is odd. In C it's: #include int main(void) { printf("%zu\n", sizeof (int *)); return 0; }
Re: Everything you need to know about pointers in C (2010)
#10> void pointers are incremented or decremented by 1 byte. No, void pointer arithmetic is not allowed by the C standard: https://stackoverflow.com/questions/3523145/pointer-arithmet...