Click here to Skip to main content
15,889,527 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: False selection... Pin
ely_bob12-Oct-10 5:13
professionalely_bob12-Oct-10 5:13 
GeneralRe: False selection... Pin
James H12-Oct-10 4:02
James H12-Oct-10 4:02 
GeneralRe: False selection... Pin
LockH12-Oct-10 4:13
LockH12-Oct-10 4:13 
GeneralRe: False selection... Pin
waldemar.sauer@aitmetis.com12-Oct-10 7:51
waldemar.sauer@aitmetis.com12-Oct-10 7:51 
GeneralRe: False selection... Pin
lordofawesome12-Oct-10 8:26
lordofawesome12-Oct-10 8:26 
GeneralRe: False selection... Pin
waldemar.sauer@aitmetis.com12-Oct-10 8:44
waldemar.sauer@aitmetis.com12-Oct-10 8:44 
GeneralRe: False selection... Pin
lordofawesome12-Oct-10 8:49
lordofawesome12-Oct-10 8:49 
GeneralRe: False selection... Pin
waldemar.sauer@aitmetis.com12-Oct-10 9:06
waldemar.sauer@aitmetis.com12-Oct-10 9:06 
It's hard for me to tell what the answer would be inside a Java interpreter. I suspect that the difference will be small.

I doubt that declaring local variables vs. not declaring will actually make a difference in C/C++. Local variables get assigned machine registers, and they may actually not require stack locations at all.

In fact, with a decent optimizing compiler, the following snippets will compile to the same code:
void fx(int x)
{
    doSomethingWithX(x);
}


and

void fx(int x)
{
    int descriptionForX = x;
    doSomethingWithX(descriptionForX);
}


The reason is that the 'descriptionForX' variable will be coalesced so that it uses the same register as x, and will subsequently be removed by the compiler.
GeneralRe: False selection... Pin
lordofawesome12-Oct-10 9:16
lordofawesome12-Oct-10 9:16 
GeneralRe: False selection... Pin
calamus7712-Oct-10 17:55
calamus7712-Oct-10 17:55 
GeneralRe: False selection... Pin
lordofawesome12-Oct-10 23:24
lordofawesome12-Oct-10 23:24 
GeneralRe: False selection... Pin
calamus7714-Oct-10 15:14
calamus7714-Oct-10 15:14 
GeneralRe: False selection... Pin
werD13-Oct-10 3:54
werD13-Oct-10 3:54 
GeneralRe: False selection... Pin
lordofawesome13-Oct-10 6:42
lordofawesome13-Oct-10 6:42 
GeneralRe: False selection... Pin
Member 451724015-Oct-10 2:39
Member 451724015-Oct-10 2:39 
GeneralRe: False selection... Pin
lordofawesome15-Oct-10 4:17
lordofawesome15-Oct-10 4:17 
GeneralRe: False selection... Pin
supercat911-Oct-10 8:30
supercat911-Oct-10 8:30 
GeneralRe: False selection... Pin
Phil J Pearson11-Oct-10 1:50
Phil J Pearson11-Oct-10 1:50 
GeneralRe: False selection... Pin
David Skelly11-Oct-10 1:53
David Skelly11-Oct-10 1:53 
GeneralRe: False selection... Pin
lordofawesome11-Oct-10 4:28
lordofawesome11-Oct-10 4:28 
GeneralRe: False selection... Pin
PIEBALDconsult11-Oct-10 15:44
mvePIEBALDconsult11-Oct-10 15:44 
GeneralRe: False selection... Pin
ghle12-Oct-10 16:09
ghle12-Oct-10 16:09 
GeneralRe: False selection... Pin
ghle12-Oct-10 16:28
ghle12-Oct-10 16:28 
GeneralRe: False selection... Pin
_Erik_15-Oct-10 5:19
_Erik_15-Oct-10 5:19 
GeneralRe: False selection... Pin
ghle17-Oct-10 14:45
ghle17-Oct-10 14:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.