1. quick syntax question

can someone explain to me what's happening here plz?

Code:
`*(s->top)++=c;`
I know s is a pointer to a struct, so *(s->top) is the top value of the struct s points to.

I don't understand what ++= means though.

2. Space it out a little and it might become more obvious:
Code:
`*(s->top)++ = c;`

3. It adds one to the position of the pointer (s->top), altho I think it would be better written as:

*((s->top)++)) = c;

since it might instead add one to the value of s->top (which is pointless in an assignment).

I'd have to do a quick experiment to tell the difference.

4. Dont you think a * with (s->top) is illegal coz the value of top will be given by s->top if top is a member of struct having pointer s?

5. Originally Posted by BEN10
Dont you think a * with (s->top) is illegal coz the value of top will be given by s->top if top is a member of struct having pointer s?
Not if member "top" is also a pointer.
Code:
```struct {
int *top```

6. Originally Posted by MK27
Not if member "top" is also a pointer.
Code:
```struct {
int *top```
Ohhhhh......I was assuming it just an int.

7. Originally Posted by MK27
altho I think it would be better written as:

*((s->top)++)) = c;

since it might instead add one to the value of s->top (which is pointless in an assignment).
I feel that if you think that *p++ might be misconstrued as (*p)++, then you should break it up instead of trying to clarify with parentheses. The parentheses spoil the fun of having such a condensed expression, in my opinion (so... *s->top++=c; FTW!)

8. so if I get it right *(s->top)++=c; equals

Code:
```int *ptr = s->top;
*ptr=c;
ptr++;
s->top=ptr;```
?

9. In effect, yes. Alternatively:
Code:
```*(s->top) = c;
(s->top)++;```

10. Originally Posted by laserlight
In effect, yes. Alternatively:
Code:
```*(s->top) = c;
(s->top)++;```
Ixnay. The post-increment will occur before the assignment. If the point is to add one to the value of s->top, the ++ does nothing in the end.

If the point is to make s->top point to what was the equivalent of s->top[1], then that space better be part of s, because it will be set to the value of c.

11. Originally Posted by MK27
Ixnay. The post-increment will occur before the assignment.
The post-increment does not happen until after s->top has been fully evaluated. Whether it occurs before or after the assignment does not change the result.

The line of code stores 'c' into the location pointed to by s->top, then increments s->top.

12. Originally Posted by brewbuck
The post-increment does not happen until after s->top has been fully evaluated. Whether it occurs before or after the assignment does not change the result.

The line of code stores 'c' into the location pointed to by s->top, then increments s->top.
Sorry -- I was looking at this order of precedence table:

C Operator Precedence Table

However, it's obviously wrong as even the simple:
Code:
`int a = 5, b = a++;`
demonstrates (which if it were my code, I'd have been writing it and noticed )

13. hmm... I sent you this in my PM, but anyway...

Originally Posted by MK27
I glanced at an "order of precedence" table here:

C Operator Precedence Table

wherein ++ has higher precedence than =, but obviously, as a couple of quick experiments demonstrated, that is not true.
It is true that postfix increment operator has a higher precedence than the copy assignment operator. But what that means is that this:
Code:
`a = b++;`
should be interpreted as:
Code:
`a = (b++);`
rather than:
Code:
`(a = b)++;`
whereas this:
Code:
`a = b, c;`
should be interpreted as:
Code:
`(a = b), c;`
not:
Code:
`a = (b, c);`
since the copy assignment operator has a higher precedence than the comma operator.

EDIT:
Perhaps you are missing a fundamental point: the result of a++ is the value of a before the increment.

14. Originally Posted by MK27
Sorry -- I was looking at this order of precedence table:

C Operator Precedence Table

However, it's obviously wrong as even the simple:
Code:
`int a = 5, b = a++;`
demonstrates (which if it were my code, I'd have been writing it and noticed )
Precedence controls order of binding, not order of operations. It specifies which operations will occur to which expressions, not when they will occur. The order of operations is controlled by associativity and sequence points. Operators in different precedence classes are treated independently when determining associativity.

On top of all that, the compiler can evaluate the expression any way it likes, so long as the result is the same as if it had done it in the order defined by the language.

The code in question looks like it's pushing something onto a stack.

15. Well that is very deceptive then isn't it

I guess the best means of resolving uncertainty is still actual experimentation.