Advertisement
jacknpoe

Clareza no código: uso de macro e resultado.

Oct 26th, 2013
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3.  
  4. typedef struct estrutura{
  5.     char caracter;  int inteiro;
  6. } estrutura;
  7.  
  8. #define ESTRUTURA(index) ( (estrutura *) buffer) [ (long long) (index) ]
  9.  
  10. inline int soma( int i1, int i2) { return i1 + i2; }
  11.  
  12. int main( void){
  13.     void *buffer;
  14.  
  15.     buffer = (void *) malloc( sizeof( estrutura) * 2);
  16.  
  17.     ESTRUTURA( 0).caracter = 10;   ESTRUTURA( 1).inteiro = 15;
  18.  
  19. // COM MACRO
  20.     std::cout << soma( ESTRUTURA(0).caracter, ESTRUTURA(1).inteiro) << std::endl;
  21.  
  22. // SEM MACRO (MESMO QUE ACIMA)
  23.     std::cout << soma( (( (estrutura *) buffer) [ 0]).caracter,
  24.                        (( (estrutura *) buffer) [ 1]).inteiro ) << std::endl;
  25.     free( buffer);
  26.     return 0;
  27. }
  28.  
  29. ————————————————————————————————————————————————————————————————————————————————————————————————————————————
  30. ————————————————————————————————————————————————————————————————————————————————————————————————————————————
  31.  
  32. CÓDIGO GERADO PELO COMPILADOR (TDM-GCC 4.7.1 32 bits, Orwell Dev C++ Windows)
  33.  
  34. COM MACRO:
  35.  
  36.    0x0040153b <+59>:    add    eax,0x8
  37.    0x0040153e <+62>:    mov    edx,DWORD PTR [eax+0x4]
  38.    0x00401541 <+65>:    mov    eax,DWORD PTR [ebp-0xc]
  39.    0x00401544 <+68>:    movzx  eax,BYTE PTR [eax]
  40.    0x00401547 <+71>:    movsx  eax,al
  41.    0x0040154a <+74>:    mov    DWORD PTR [esp+0x4],edx
  42.    0x0040154e <+78>:    mov    DWORD PTR [esp],eax
  43.    0x00401551 <+81>:    call   0x4157e0 <soma(int, int)>
  44.    0x00401556 <+86>:    mov    DWORD PTR [esp],eax
  45.    0x00401559 <+89>:    mov    ecx,0x47bf60
  46.    0x0040155e <+94>:    call   0x4450f0 <std::ostream::operator<<(int)>
  47.    0x00401563 <+99>:    sub    esp,0x4
  48.    0x00401566 <+102>:   mov    DWORD PTR [esp],0x46dd30
  49.    0x0040156d <+109>:   mov    ecx,eax
  50.    0x0040156f <+111>:   call   0x444df0 <std::ostream::operator<<(std::ostream& (*)(std::ostream&))>
  51.    0x00401574 <+116>:   sub    esp,0x4
  52.    0x00401577 <+119>:   mov    eax,DWORD PTR [ebp-0xc]
  53.  
  54.  
  55. SEM MACRO:
  56.  
  57.    0x0040157a <+122>:   add    eax,0x8
  58.    0x0040157d <+125>:   mov    edx,DWORD PTR [eax+0x4]
  59.    0x00401580 <+128>:   mov    eax,DWORD PTR [ebp-0xc]
  60.    0x00401583 <+131>:   movzx  eax,BYTE PTR [eax]
  61.    0x00401586 <+134>:   movsx  eax,al
  62.    0x00401589 <+137>:   mov    DWORD PTR [esp+0x4],edx
  63.    0x0040158d <+141>:   mov    DWORD PTR [esp],eax
  64.    0x00401590 <+144>:   call   0x4157e0 <soma(int, int)>
  65.    0x00401595 <+149>:   mov    DWORD PTR [esp],eax
  66.    0x00401598 <+152>:   mov    ecx,0x47bf60
  67.    0x0040159d <+157>:   call   0x4450f0 <std::ostream::operator<<(int)>
  68.    0x004015a2 <+162>:   sub    esp,0x4
  69.    0x004015a5 <+165>:   mov    DWORD PTR [esp],0x46dd30
  70.    0x004015ac <+172>:   mov    ecx,eax
  71.    0x004015ae <+174>:   call   0x444df0 <std::ostream::operator<<(std::ostream& (*)(std::ostream&))>
  72.    0x004015b3 <+179>:   sub    esp,0x4
  73. => 0x004015b6 <+182>:   mov    eax,DWORD PTR [ebp-0xc]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement