请帮助理解这一点 [英] Help with understanding this please
问题描述
我正在尝试使用此代码定义一个名为temp的结构。请用
来解释一下这不起作用:-)
#include< stdio.h>
# include< stdlib.h>
struct t_node_n {
char * word;
int match;
struct t_node_n * left;
struct t_node_n * right;
};
struct t_node_n * temp =(struct t_node_n *)malloc(sizeof(struct
t_node_n)); / *错误:初始化元素不是常数* /
int main {};
所以,这就是我想的* *我正在做。
创建一个类型为struct t_node_n的指针,称为temp。
定义指针temp通过调用malloc ....我认为**
给出了指针memory。指向,从而定义它?
显然这些想法远离基础!!
谢谢:-)
I am trying to define a struct called temp, using this code. Please be
kind in explaining with this is not working :-)
#include <stdio.h>
#include <stdlib.h>
struct t_node_n{
char *word;
int match;
struct t_node_n *left;
struct t_node_n *right;
};
struct t_node_n *temp = (struct t_node_n *) malloc(sizeof(struct
t_node_n)); /* error: initializer element is not constant */
int main {};
So, this is what I **thought** I was doing.
Create a pointer of type struct t_node_n called "temp".
Define the pointer "temp" by calling malloc....which I **thought**
gives the pointer "memory" to point to, thus defines it?
Clearly these thoughts are way off base!!
Thanks :-)
推荐答案
mdh说:
mdh said:
我正在尝试使用此代码定义一个名为temp的结构。请用
来解释一下这不起作用:-)
#include< stdio.h>
# include< stdlib.h>
struct t_node_n {
char * word;
int match;
struct t_node_n * left;
struct t_node_n * right;
};
struct t_node_n * temp =(struct t_node_n *)malloc(sizeof(struct
t_node_n));
I am trying to define a struct called temp, using this code. Please be
kind in explaining with this is not working :-)
#include <stdio.h>
#include <stdlib.h>
struct t_node_n{
char *word;
int match;
struct t_node_n *left;
struct t_node_n *right;
};
struct t_node_n *temp = (struct t_node_n *) malloc(sizeof(struct
t_node_n));
更好:struct t_node_n * temp = malloc(sizeof * temp);
更清洁,更紧凑,更少维护麻烦。
Better: struct t_node_n *temp = malloc(sizeof *temp);
Cleaner, tighter, less maintenance hassle.
/ *错误:初始化元素不是常数* /
/* error: initializer element is not constant */
是的。你不能在函数内调用函数。
Yes. You can''t call a function except from within a function.
int main {};
int main {};
嗯。我想你已经醒了太久了。休息一下。 :-)
-
Richard Heathfield< http://www.cpax.org.uk>
电子邮件:-http:// www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
Hmmm. I think you''ve been awake far too long. Get some rest. :-)
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
>
嗯。我想你已经醒了太久了。休息一下。 :-)
>
Hmmm. I think you''ve been awake far too long. Get some rest. :-)
:-)我认为你是对的
:-) I think you are correct
8月30日早上7点11分,Richard Heathfield< r ... @ see.sig.invalidwrote:
On Aug 30, 7:11*am, Richard Heathfield <r...@see.sig.invalidwrote:
mdh说:
mdh said:
>
>
struct t_node_n {
char * word;
int match;
struct t_node_n * left;
struct t_node_n * right;
};
struct t_node_n{
char *word;
int match;
struct t_node_n *left;
struct t_node_n *right;
};
struct t_node_n * temp =(struct t_node_n *)malloc(sizeof(struct
t_node_n));
struct t_node_n *temp = (struct t_node_n *) malloc(sizeof(struct
t_node_n));
更好:struct t_node_n * temp = malloc(sizeof * temp);
更清洁,更紧凑,更少维护麻烦。
Better: struct t_node_n *temp = malloc(sizeof *temp);
Cleaner, tighter, less maintenance hassle.
理查德...在我休息之前让睡眠变得平静!!我可以问你为什么没有给b
$ b从malloc到类型struct t_node n *。 K& R
在第142页上对此进行了大量讨论。
一如既往地谢谢。
Richard...before I rest so that sleep can be calm!!, may I ask why you
have not cast the return from malloc to type "struct t_node n *). K&R
devote quite a discussion to this on page 142.
Thanks as always.
这篇关于请帮助理解这一点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!