TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Peter Collis
from: david nugent
date: 1994-05-03 08:09:34
subject: QC25 problem

> I have 2 questions 1 regarding what i think is a bug in the QC25 IDE
 > the other is using "++" to inc an integer pointed to.

 > 1. [..]

Can't help with that one, sorry.

 > 2. My second problem involves incrementing a integer by reference,
 >    see code snippet below.

 > void inc_integer(int *myint);

 > int main() {

 >     int counter = 1;
 >     inc_integer(&counter);
 >     return 0;
 > }

 > void inc_integer(int *myint) {

 >     *myint++;
 >     return;
 > }

 > in the code above the offset address is shifted by 2 bytes instead of
 > the value pointed to even though i use the '*' to inc whats pointed
 > to not the pointer value, if i use "*myint+=1" all works ok it's just
 > the "++" doesn't.


Two operations are being performed here; the dereference and the increment.
If you grab your K&R2 or QC reference manual and examine the order of
precedence of operators, you'll find that increment '++' binds tighter than
'*' (dereference), so it is interpreted as:

    *(myint++);

In fact, the dereference does nothing here and would usually be discarded
causing the compiler to complain (not error) because of 'unused code'.

Try using parens:

    (*myint)++;


  cheers,
  david

---

* Origin: Unique Computing Pty Ltd (3:632/348)
SEEN-BY: 50/99 54/54 620/243 623/625 630 632/103 301 348 365 386 998 633/371
SEEN-BY: 634/384 635/210 502 503 541 544 636/100 670/206 711/409 430 807 808
SEEN-BY: 711/809 932 934 712/623 713/888 714/906 800/1
@PATH: 632/348 635/503 50/99 54/54 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.