This question is a test of concept of the question in Why is it valid to define a type as pointer to an undefined struct in C?
I know that it is not a useful program, please abstain to say "you didn't define this and that". The discussion was about pointer aritmethic on an opaque type. Sorry for bothering too many people, but the answers can be useful anyway.
This program:
struct st1 {
int a,b;
};
struct st2;
typedef struct st2 *foo;
typedef struct foo *bar;
void main(void) {
struct st1 *net=0;
foo ft1=0;
bar test=0;
net++;
ft1++;
test++;
}
when compiled with gcc gives the following:
pc:~$ cc tmp2.c
tmp2.c: In function 'main':
tmp2.c:17:6: error: increment of pointer to unknown structure
ft1++;
^
tmp2.c:17:3: error: arithmetic on pointer to an incomplete type
ft1++;
^
tmp2.c:18:7: error: increment of pointer to unknown structure
test++;
^
tmp2.c:18:3: error: arithmetic on pointer to an incomplete type
test++;
^
I would like to understand better what is happening here, because of course pointer aritmethic is a bit difficult when not knowing what the pointer points to...