I might not have had a counterexample when I got the reply "A pointer is just an address, what's the difficulty?" but I didn't really buy such a simple explanation and at assembly code it's not obvious what's a pointer for 2 different C programs that generate the same assembly.
cat pelle.s valle.s
.file "pelle.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
movl $0, %eax
popl %ebp
.cfi_def_cfa 4, 4
.cfi_restore 5
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
.section .note.GNU-stack,"",@progbits
.file "valle.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
movl $0, %eax
popl %ebp
.cfi_def_cfa 4, 4
.cfi_restore 5
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
.section .note.GNU-stack,"",@progbits
1) An address to a variable is &var1
and the pointer is int* var1
written differently than the address. 2) When I compile 2 C programs where the only difference is pointing then there is no difference in the assembly:
$ diff pelle.c valle.c ;cat pelle.c valle.c;diff pelle.s valle.s
3c3
< int * pelle;
---
> int valle;
#include <stdio.h>
int main(void) {
int * pelle;
return 0;
}
#include <stdio.h>
int main(void) {
int valle;
return 0;
}
1c1
< .file "pelle.c"
---
> .file "valle.c"
But what conclusions can be drawn from no difference in generated assembly to investigate the "simple and obvious difference" between a pointer declaration and other type? Is the simplistic answer right all along, a pointer is just a variable and there's no point in more analysis? Or that the difference between a pointer and a variable is a case of "sugar" since the types are removed at assembly level where there is no difference? Will a difference in the generated assembly show a diff if I use pointers as arguments to a function and there will indeed be a difference for some pointer usage and this example is too trivial and can't be generalized? So when types are removed in the generated assembly, can I conclude that type difference indeed will result in a difference i nthe generated assembly for a non-trivial example e.g. pointers as arguments and this example is not very good since it looks like the generated assembly disregards typing, while type difference such as this will make a difference in generated assembly for another example?
int valle;
int * pelle;
Assembler
.data
.align 2
.global valle
valle: .word 0
.data
.align 2
.global pelle
pelle: .word 0