SourceComment: Declare variable nearest to its first use

Dear all

I saw this style in Lippman’s C++ book
const PackedHostCaches * PackedHostCaches::findIn (const GgepBlock &ggepBlock) {
    const PackedHostCaches *res = 0;
foreach (const Ggep *extension, ggepBlock.extensions()) {
        res = dynamic_cast (extension);
       if (res != 0)
return res;

}
return 0;
}

With

const PackedHostCaches * PackedHostCaches::findIn (const GgepBlock &ggepBlock) {

foreach (const Ggep *extension, ggepBlock.extensions()) {

if( const PackedHostCaches* res = dynamic_cast (extension) )

return res;

}

return 0;
– cheers atul

Would you like to post a relpy?


This post starts a thread.
Follow-ups:
Re: SourceComment: Declare variable nearest to its first use
Yes Atul, I totally agree with you! You have a patch for that already? Regards, Peter atul wrote:Dear all I saw this style in Lippman's C++ book const PackedHostCaches * PackedHostCaches::findIn (const GgepBlock &ggepBlock) { (more...)