dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: --index or index--

  1. #1
    Join Date
    Jun 2002
    Location
    Lyman ME - USA | Oneonta NY - USA
    Posts
    399

    --index or index--

    quick question...prolly a fast answer but here goes...why would code be this:
    Code:
     buffer[index - bufIndex] = '\0';
    --index;
    instead of:
    Code:
     buffer[index-- - bufIndex] = '\0';
    because my understanding is that the later is the same thing as the first...

    thanks for the help

    - nc
    "In a world without walls and barriers, what need is there for windows and gates!" - a mac ad
    "What was the best thing before sliced bread and when did sliced bread go out of existence?" - me
    "Software is like sex, it's better when it's free." - Linus Torvalds <- gotten from Andreas Masur


    Live Penguine! - Tux the linux mascot
    Vivez le penguine!, íViva en penguine!, Lang lebe der Pinguin!, Viva no penguine!, Viva sul penguine!

  2. #2
    Join Date
    Sep 2000
    Location
    Antwerp, Belgium
    Posts
    101
    Just some thoughts:

    I myself tend to put those things on several lines, for readability and for debugging purposes.
    Now you can put a breakpoint on each line, or watch more closely what happens.

    The compiler optimizes these things anyway (if you want), so there is no performance problem anyhow.

    This is not a to difficult thing, but i've seen monsters of expressions that would take me a long time to figure out. Mostly had to take a look at them because they where wrong!!

    i'm also in the habbit of using a lot of parenthesis, such that i'm really sure that the operators are evaluated exactly the way i want.

    I once read (at school still, i think) that operator precedence is dependent on the compiler. Therefor i make sure the statement will be always evaluated the same.

    Hope this clears it up a bit,

    Steven Roelants

  3. #3
    Join Date
    Aug 2001
    Location
    North Bend, WA
    Posts
    1,947
    Yep they do the same thing.

  4. #4
    Join Date
    Jun 2002
    Location
    Lyman ME - USA | Oneonta NY - USA
    Posts
    399
    ok thats what i thought and i figured that it was set up that way for readability but i'm a java programmer now and i'm teaching myself VC++/C++/C with some breif knowledge of ASM and my knowledge of Java it's made my transition MUCH easier but i want to be sure that things will do the same thing...
    You are right about the parens thing as well...i use parens all the time specially with C++ and pointers<crucial to>
    anyway...
    thanks for the help

    - nc
    "In a world without walls and barriers, what need is there for windows and gates!" - a mac ad
    "What was the best thing before sliced bread and when did sliced bread go out of existence?" - me
    "Software is like sex, it's better when it's free." - Linus Torvalds <- gotten from Andreas Masur


    Live Penguine! - Tux the linux mascot
    Vivez le penguine!, íViva en penguine!, Lang lebe der Pinguin!, Viva no penguine!, Viva sul penguine!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)