Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I previously replied with the below answer. But then I saw that I misinterpreted several information and gave an incorrect answer. Just out of curiosity, I did the same test with VS2008 and I got different results. This is just brain exercise...</p> <pre> Why do you need the second one ? Both headers say the same thing. And it does not even matter if you write 0 or NULL or ((void *)0) All of them will take 8 bytes. </pre> <p>I did a quick test on a 64-bit platform with GCC 4.1.3</p> <pre><code>#include &lt;string.h&gt; void str_concat(char *po_buf, int pi_max, ...) { strcpy(po_buf, "Malkocoglu"); /* bogus */ } int main() { char buf[100]; str_concat(buf, 100, "abc", 1234LL, "def", 5678LL, "ghi", 2345LL, "jkl", 6789LL, "mno", 3456LL, 0, "pqx", 0); return 1; } </code></pre> <p>And this is the assembly generated by the compiler...</p> <pre><code>main: .LFB3: pushq %rbp .LCFI3: movq %rsp, %rbp .LCFI4: subq $192, %rsp .LCFI5: leaq -112(%rbp), %rdi movl $0, 64(%rsp) 0 movq $.LC2, 56(%rsp) "pqx" movl $0, 48(%rsp) 0 movq $3456, 40(%rsp) 3456LL movq $.LC3, 32(%rsp) "mno" movq $6789, 24(%rsp) 6789LL movq $.LC4, 16(%rsp) "jkl" movq $2345, 8(%rsp) 2345LL movq $.LC5, (%rsp) "ghi" movl $5678, %r9d 5678LL movl $.LC0, %r8d "def" movl $1234, %ecx 1234LL movl $.LC1, %edx "abc" movl $100, %esi 100 movl $0, %eax call str_concat movl $1, %eax leave ret </code></pre> <p>Notice all the stack displacements are 8 byte...</p> <pre> Compiler treats 0 as it was a 32-bit data-type. Although it does the correct displacement on the stack pointer, the value pushed should not be 32-bit ! </pre> <p>I did the same test with VS2008 , the assembly output is as follows :</p> <pre><code>mov QWORD PTR [rsp+112], 0 lea rax, OFFSET FLAT:$SG3597 mov QWORD PTR [rsp+104], rax mov QWORD PTR [rsp+96], 0 mov QWORD PTR [rsp+88], 3456 ; 00000d80H lea rax, OFFSET FLAT:$SG3598 mov QWORD PTR [rsp+80], rax mov QWORD PTR [rsp+72], 6789 ; 00001a85H lea rax, OFFSET FLAT:$SG3599 mov QWORD PTR [rsp+64], rax mov QWORD PTR [rsp+56], 2345 ; 00000929H lea rax, OFFSET FLAT:$SG3600 mov QWORD PTR [rsp+48], rax mov QWORD PTR [rsp+40], 5678 ; 0000162eH lea rax, OFFSET FLAT:$SG3601 mov QWORD PTR [rsp+32], rax mov r9d, 1234 ; 000004d2H lea r8, OFFSET FLAT:$SG3602 mov edx, 100 ; 00000064H lea rcx, QWORD PTR buf$[rsp] call ?str_concat@@YAXPEADHZZ ; str_concat </code></pre> <p>This time compiler generates different code and it treats 0 as an 64-bit data-type (notice the QWORD keyword). Both the value and stack displacement is correct. VS and GCC behaves differently.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload