Robison, Arch
2014-Apr-04 17:39 UTC
[LLVMdev] Why "I = ++I" instead of "++I" in COFFDump.cpp ?
tools/llvm-objdump/COFFDump.cpp has two loops that advance the loop iterator using "I = ++I" instead of the usual "++I". For example: import_directory_iterator I = Obj->import_directory_begin(); import_directory_iterator E = Obj->import_directory_end(); if (I == E) return; outs() << "The Import Tables:\n"; for (; I != E; I = ++I) { ... } Is there a reason for writing "I = ++I" instead of "++I" ? - Arch D. Robison
David Blaikie
2014-Apr-04 17:44 UTC
[LLVMdev] Why "I = ++I" instead of "++I" in COFFDump.cpp ?
Not that I know of - and if there is... we've got issues. So change it & find out? :) On Fri, Apr 4, 2014 at 10:39 AM, Robison, Arch <arch.robison at intel.com> wrote:> tools/llvm-objdump/COFFDump.cpp has two loops that advance the loop iterator using "I = ++I" instead of the usual "++I". For example: > > import_directory_iterator I = Obj->import_directory_begin(); > import_directory_iterator E = Obj->import_directory_end(); > if (I == E) > return; > outs() << "The Import Tables:\n"; > for (; I != E; I = ++I) { > ... > } > > Is there a reason for writing "I = ++I" instead of "++I" ? > > - Arch D. Robison > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reid Kleckner
2014-Apr-04 17:44 UTC
[LLVMdev] Why "I = ++I" instead of "++I" in COFFDump.cpp ?
Looks like a bug. This can probably be simplified with C++11. On Fri, Apr 4, 2014 at 10:39 AM, Robison, Arch <arch.robison at intel.com>wrote:> tools/llvm-objdump/COFFDump.cpp has two loops that advance the loop > iterator using "I = ++I" instead of the usual "++I". For example: > > import_directory_iterator I = Obj->import_directory_begin(); > import_directory_iterator E = Obj->import_directory_end(); > if (I == E) > return; > outs() << "The Import Tables:\n"; > for (; I != E; I = ++I) { > ... > } > > Is there a reason for writing "I = ++I" instead of "++I" ? > > - Arch D. Robison > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140404/9fec47a0/attachment.html>
Oops, meant to send this to the mailing list instead of to Reid privately. (Why cc the mailing list instead of just sending to the mailing list?) In article <CACs=tyJ6zaHeiS0eNhBkdcZE--JY4k7yH9_P1yFbGqod6uymMw at mail.gmail.com>, Reid Kleckner <rnk at google.com> writes:> Looks like a bug. This can probably be simplified with C++11. > > On Fri, Apr 4, 2014 at 10:39 AM, Robison, Arch <arch.robison at intel.com>wrote: > > > for (; I != E; I = ++I) { > > ... > > } > > > > Is there a reason for writing "I = ++I" instead of "++I" ?I don't see how it's a bug because functionality isn't impacted by this. It's simply a redundant assignment. I also don't see what C++11 has to do with this. i = i; has always been legal since the very first implementation of C and has always been a pointless expression. Had the code been: i = i++; then we would have had a real problem since i++ returns the old value of i before it was incremented and the loop would be infinite. -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://ComputerGraphicsMuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>
Seemingly Similar Threads
- [LLVMdev] Why "I = ++I" instead of "++I" in COFFDump.cpp ?
- [LLVMdev] Why "I = ++I" instead of "++I" in COFFDump.cpp ?
- [LLVMdev] [Patch] WinCOFFObjectWriter: fix for storing pointer to string table in header name field
- [LLVMdev] [Patch] WinCOFFObjectWriter: fix for storing pointer to string table in header name field
- [LLVMdev] [Patch] WinCOFFObjectWriter: fix for storing pointer to string table in header name field