gcc 4.4.3 c89堆栈转储访问malloc字符数组
我有以下源代码。在printf上获取堆栈转储。
char **devices;
devices = malloc(10 * sizeof(char*));
strcpy(devices[0], "smxxxx1");
printf("[ %s ]\n", devices[0]); /* Stack dump trying to print */
我想这应该创建一个像这样的char数组。
devices[0]
devices[1]
devices[2]
devices[4]
etc
而且每个元素都可以存储我的字符串。
===
for(i = 0; i < 10; i++)
{
devices[i] = malloc(strlen("smxxxx1")+1);
}
对于引发几个几乎相同的答案的问题的荣誉。 – sum1stolemyname 2010-05-12 09:01:22
堆栈转储或核心转储? – 2010-05-12 11:17:19
@Matt Curtis:我似乎记得gcc生成的程序为win32生成堆栈转储到他们在出现某种类型的错误时运行的dos框。它似乎没有在我当前的设置上做到这一点,虽然(明戈,Vista,x86-32)。 – nategoose 2010-05-12 19:13:15