关于“定义”的问题和“malloc” [英] Question about "define" and "malloc"
问题描述
CSS白色:
奇怪的是,我找到了定义无法使用malloc。我的
编译器会一起说解析错误。
有谁可以告诉我原因?
----- --------------------
#define MAX 10000
.......
int main(void){
.....
char * temp =(char *)malloc(MAX * sizeof(char));
.....
系统(暂停);
返回0;
}
遵守时,错误。
寻找解释。
CSS white here:
Simply strange, I found "define" can not work with "malloc". Together my
complier will say "parse error".
Could anyone tell me why?
-------------------------
#define MAX 10000
.......
int main(void){
.....
char * temp=(char *)malloc(MAX*sizeof(char));
.....
system("pause");
return 0;
}
when complying, wrong.
look for explanation.
推荐答案
陈树生写道:
Chen Shusheng wrote:
CSS白色:
CSS white here:
什么?
what?
简单地说,我找到了定义无法使用malloc。
Simply strange, I found "define" can not work with "malloc".
你错了
you are mistaken
我的编译器会说解析错误。
有谁可以告诉我为什么?
Together my complier will say "parse error".
Could anyone tell me why?
将来请发一个* * * * * * * *(((((((((((((((((((((( $ b计划。不要把......放在一起。在小程序中。
这个温和编辑的代码版本为我编译
#include< stdlib.h>
#define MAX 10000
int main(无效)
{
char * temp = (char *)malloc(MAX * sizeof(char));
// system(" pause");
返回0;
}
in future please post a *comple* *compilable* (well as close as you
can!)
program. Don''t put "...." in small programs.
This mildly edited version of your code compiles for me
#include <stdlib.h>
#define MAX 10000
int main(void)
{
char *temp = (char*)malloc (MAX * sizeof(char));
// system("pause");
return 0;
}
------------------------ -
#define MAX 10000
......
int main(无效){
。 ...
char * temp =(char *)malloc(MAX * sizeof(char));
-------------------------
#define MAX 10000
......
int main(void){
....
char * temp=(char *)malloc(MAX*sizeof(char));
不要施放malloc。根据定义,char的sizeof为1,所以写上面的
char * temp = malloc(MAX);
我也被你的布局所欺骗因为我比你更喜欢空白
使用。
don''t cast malloc. sizeof of char is 1 by definition so write the above
char * temp = malloc (MAX);
I also fooled with your layout as I prefer more whitespace than you
use.
....
system(暂停 );
....
system("pause");
非标准
non-standard
返回0;
}
遵守时,错了。
寻找解释。
return 0;
}
when complying, wrong.
look for explanation.
我怀疑你省略了包括stlib.h
-
Nick Keighley
I suspect you ommitted to include stlib.h
--
Nick Keighley
它很适合我的主机......
你能展示你的源代码吗?
>
这是我的测试代码:
#include< stdlib.h>
#include< stdio.h>
#define MAX 10000
int main()
{
char * tmp;
tmp =(char *)malloc(MAX * sizeof(char));
printf(" done\\\
");
返回0;
}
并在Linux上使用gcc版本3.4.4进行编译
[monnand @ monnand-host test]
it works on my host very well...
could you show your source code?
here is my test code:
#include <stdlib.h>
#include <stdio.h>
#define MAX 10000
int main()
{
char *tmp;
tmp = (char *)malloc(MAX*sizeof(char));
printf("done\n");
return 0;
}
and compile it on Linux with gcc version 3.4.4
[monnand@monnand-host test]
gcc 1.c
[monnand @ monnand-host test]
gcc 1.c
[monnand@monnand-host test]
这篇关于关于“定义”的问题和“malloc”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!