The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 23, 2019, 01:52:35 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Book bug: Beginning Objective C Programming  (Read 2344 times)
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« on: May 13, 2011, 08:57:20 AM »

Going back through the book now for a couple details, stopped at operators.

Quote
Addition by 1 is such a common operation in programs that a special operator was created for this purpose. Therefore the expression ++i is equivalent to the expression n = n+ 1
...
Some programmers prefer to put the ++ or -- after the variable name, as n++ or counter--. This is acceptable and a matter of personal preference

Shocked

Personal preference?!?!? NO DISCUSSION about the difference in behavior. So distressed was I that ++n was no different than n++ I had to throw together a quickie to test it ...

Code:
int i=1;
printf("i=%i, ", i);
printf("i=%i, ", ++i);
printf("i=%i, ", i++);
printf("i=%i\n", i);

... which provided the satisfying result of "i=1, i=2, i=2, i=3" just as it should. In chapter 13, after about 30 pages of somewhat confusing discussion about why you might want to reference an integer as a pointer rather than a regular variable then it goes into char strings and finally handles the difference between pre and post inc/dec of a value as such:

Quote
As a final example on this topic before we present a program, it textptr is a char pointer the expression *(++textptr) first increments textptr then fetches the character it points to, whereas the expression *(textptr++) fetches the character that textptr points to before its value is incremented.

Not very clear, at best.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #1 on: May 13, 2011, 03:07:47 PM »

thats why i dont read manuals. It relies too much on the writer being smart.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #2 on: May 18, 2011, 12:00:16 AM »

As a final example on this topic before we present a program, it textptr is a char pointer the expression *(++textptr) first increments textptr then fetches the character it points to, whereas the expression *(textptr++) fetches the character that textptr points to before its value is incremented.

Not very clear, at best.
Basically one is postfix the other is prefix.
In a nutshell why polish notation is better for programming.
And also why functional programming is better then procedural programming.
With a language like ocaml,ML etc. that sort of error could never happen.
Internally the compiler will create a loop.
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!