1
2
3
4
5
6
7
int
main()
{
	char * str = new char[32];
	str = "Hello, Piggy!";
	return 0;
}

这样是会内存泄漏的……而我一直都不知道……

1
2
3
4
5
6
7
8
9
10
11
12
.LC0:
	.string	"Hello, Piggy!"
	.text
.globl main
	.type	main, @function
main:
	andl	$-16, %esp
	subl	$32, %esp
	movl	$32, (%esp)
	call	_Znaj
	movl	%eax, 28(%esp)
	movl	$.LC0, 28(%esp) ;把str给覆盖了

不过想来也自然,因为这样是允许的,char *str = “Hello, Piggy!”;,“程序中的字符串被存放在常量存储区”不要把这句话当成耳旁风,谨记。

Tags: ,,.
Home

10 Comments so far

Leave a comment

Name(required)
Mail (required),(will not be published)
  10 + 13 = ?
Please leave these two fields as-is:
Website(recommended)

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URLs must be fully qualified (eg: http://www.dutor.net),and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.