Click here to Skip to main content
15,889,096 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: Fun with pointers in C++ Pin
James Curran26-Jun-15 5:22
James Curran26-Jun-15 5:22 
GeneralRe: Fun with pointers in C++ Pin
MarkTJohnson26-Jun-15 5:42
professionalMarkTJohnson26-Jun-15 5:42 
GeneralRe: Fun with pointers in C++ Pin
firegryphon29-Jun-15 10:02
firegryphon29-Jun-15 10:02 
GeneralRe: Fun with pointers in C++ Pin
BotReject29-Jun-15 22:58
BotReject29-Jun-15 22:58 
GeneralRe: Fun with pointers in C++ Pin
TheGreatAndPowerfulOz30-Jun-15 9:12
TheGreatAndPowerfulOz30-Jun-15 9:12 
GeneralRe: Fun with pointers in C++ Pin
James Curran30-Jun-15 10:16
James Curran30-Jun-15 10:16 
GeneralRe: Fun with pointers in C++ Pin
TheGreatAndPowerfulOz30-Jun-15 10:35
TheGreatAndPowerfulOz30-Jun-15 10:35 
GeneralRe: Fun with pointers in C++ Pin
James Curran30-Jun-15 11:24
James Curran30-Jun-15 11:24 
I was referring to the second version I posted (i.e., "the longer version", the one with nested if()s).

And that does produce identical object code. From VisualStudio 2013, Release build:

Mine:
; 21   : void Method2()
; 22   : {
; 23   :    A* pa = GetA();

  00023 e8 00 00 00 00   call    ?GetA@@YAPAHXZ     ; GetA
  00028 8b f0        mov     esi, eax

; 24   :    if (pa != NULL)

  0002a 85 f6        test    esi, esi
  0002c 74 0d        je  SHORT $LN6@wmain

; 25   :    {
; 26   :        B* pb = GetB();

  0002e e8 00 00 00 00   call    ?GetB@@YAPAHXZ     ; GetB

; 27   :        if (pb != NULL)

  00033 85 c0        test    eax, eax
  00035 74 04        je  SHORT $LN6@wmain

; 28   :            *pa = *pb;

  00037 8b 08        mov     ecx, DWORD PTR [eax]
  00039 89 0e        mov     DWORD PTR [esi], ecx
$LN6@wmain:

; 29   :    }
; 30   : }

and yours:
; 32   : void Method3()
; 33   : {
; 34   :    A* a;
; 35   :    B* b;
; 36   :    if ((a = GetA()) && (b = GetB()))

  0003b e8 00 00 00 00   call    ?GetA@@YAPAHXZ     ; GetA
  00040 8b f0        mov     esi, eax
  00042 85 f6        test    esi, esi
  00044 74 0d        je  SHORT $LN13@wmain
  00046 e8 00 00 00 00   call    ?GetB@@YAPAHXZ     ; GetB
  0004b 85 c0        test    eax, eax
  0004d 74 04        je  SHORT $LN13@wmain

; 37   :    {
; 38   :        *a = *b;

  0004f 8b 08        mov     ecx, DWORD PTR [eax]
  00051 89 0e        mov     DWORD PTR [esi], ecx
$LN13@wmain:

That's with all standard "Release mode" optimizations on, except "Whole Program Optimization" (to prevent it from inlining GetA & GetB)
Truth,

James

GeneralRe: Fun with pointers in C++ Pin
TheGreatAndPowerfulOz30-Jun-15 11:38
TheGreatAndPowerfulOz30-Jun-15 11:38 
GeneralRe: Fun with pointers in C++ Pin
Al Chak29-Jun-15 23:05
Al Chak29-Jun-15 23:05 
GeneralRe: Fun with pointers in C++ Pin
TheGreatAndPowerfulOz30-Jun-15 9:11
TheGreatAndPowerfulOz30-Jun-15 9:11 
GeneralSwitch boolean.... (reinventing if, unnecessarily) PinPopular
Rob Grainger25-Jun-15 5:25
Rob Grainger25-Jun-15 5:25 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
Jeremy Falcon25-Jun-15 5:42
professionalJeremy Falcon25-Jun-15 5:42 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
Freak3025-Jun-15 21:32
Freak3025-Jun-15 21:32 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
Jeremy Falcon26-Jun-15 3:23
professionalJeremy Falcon26-Jun-15 3:23 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
Bruce Patin26-Jun-15 6:16
Bruce Patin26-Jun-15 6:16 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
jibalt26-Jun-15 9:53
jibalt26-Jun-15 9:53 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
TheGreatAndPowerfulOz30-Jun-15 9:15
TheGreatAndPowerfulOz30-Jun-15 9:15 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
DSewhuk30-Jun-15 11:02
DSewhuk30-Jun-15 11:02 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
Daniel Pfeffer30-Jun-15 18:08
professionalDaniel Pfeffer30-Jun-15 18:08 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
ZurdoDev25-Jun-15 6:00
professionalZurdoDev25-Jun-15 6:00 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
Silvabolt25-Jun-15 6:57
Silvabolt25-Jun-15 6:57 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
Rob Grainger25-Jun-15 9:04
Rob Grainger25-Jun-15 9:04 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
DJ van Wyk25-Jun-15 19:55
professionalDJ van Wyk25-Jun-15 19:55 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) PinPopular
Kirk 1038982126-Jun-15 3:22
Kirk 1038982126-Jun-15 3:22 

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.