Skip to content

Instantly share code, notes, and snippets.

@jedisct1
Created September 17, 2011 20:50
Show Gist options
  • Save jedisct1/1224354 to your computer and use it in GitHub Desktop.
Save jedisct1/1224354 to your computer and use it in GitHub Desktop.
const char * vs const char []
#include <string.h>
size_t zob1(const char *c)
{
const char *s = "abcdefghijklmnopqrstuvwxyz";
return strspn(c, s);
}
size_t zob2(const char *c)
{
const char s[] = "abcdefghijklmnopqrstuvwxyz";
return strspn(c, s);
}
clang 2.9
=========
generates the same code for both functions:
zob1: # @zob1
.Leh_func_begin0:
movl $.L.str, %esi
jmp strspn # TAILCALL
.Leh_func_end0:
...
zob2: # @zob2
.Leh_func_begin1:
movl $.L.str, %esi
jmp strspn # TAILCALL
.Leh_func_end1:
...
.L.str:
.asciz "abcdefghijklmnopqrstuvwxyz"
gcc 4.6.1
=========
zob1:
.cfi_startproc
movl $.LC0, %esi
jmp strspn
.cfi_endproc
...
zob2:
.cfi_startproc
subq $56, %rsp
.cfi_def_cfa_offset 64
movabsq $8101815670912281193, %rdx
movabsq $8680537053616894577, %rcx
movq %fs:40, %rax
movq %rax, 40(%rsp)
xorl %eax, %eax
movq %rsp, %rsi
movabsq $7523094288207667809, %rax
movq %rdx, 8(%rsp)
movq %rax, (%rsp)
movq %rcx, 16(%rsp)
movw $31353, 24(%rsp)
movb $0, 26(%rsp)
call strspn
movq 40(%rsp), %rdx
xorq %fs:40, %rdx
jne .L5
addq $56, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 8
ret
...
.LC0:
.string "abcdefghijklmnopqrstuvwxyz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment