更多结构 [英] More structs

查看:97
本文介绍了更多结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速提问。

在下面的代码中,省略单词word,如char * word,

会产生语法错误。


在类似的非结构中声明,表达式char *应该

就够了。 ( 我认为)。是否需要添加此功能?

这个独特的结构。

像往常一样感谢。


struct key {

char * word;

int count;

};


int main(int argc,const char * argv []){


struct key keytab [] = {

" auto",0

};


}

Quick question.
In the code below, omitting the word "word", as in char *word,
produces an error of syntax.

In similar "non-struct" declarations, the expression "char *" should
suffice. ( I think). Is there a reason that one needs to add this? Is
this unique to structs.
Thanks as usual.


struct key {
char *word;
int count;
};

int main (int argc, const char * argv[]) {

struct key keytab[] = {
"auto", 0
};

}

推荐答案

mdh写道:
mdh wrote:

快速提问。

在下面的代码中,省略单词word,如char * word,

会产生语法错误。


在类似的非结构中声明,表达式char *应该

就够了。 ( 我认为)。是否需要添加此功能?是

这个结构独特。

像往常一样感谢。


struct key {

char * word;

int count;

};


int main(int argc,const char * argv []){


struct key keytab [] = {

" auto",0

};

}
Quick question.
In the code below, omitting the word "word", as in char *word,
produces an error of syntax.

In similar "non-struct" declarations, the expression "char *" should
suffice. ( I think). Is there a reason that one needs to add this? Is
this unique to structs.
Thanks as usual.

struct key {
char *word;
int count;
};

int main (int argc, const char * argv[]) {

struct key keytab[] = {
"auto", 0
};

}



如果word被省略了,你怎么会利用它命名的

指针?让我们省略一些标识符:


struct {

char *;

int;

};

int(int,const char * []){

struct [] = {

" auto", 0

};

}


这个(无效的)源代码有什么意义?它是
声明(类型)一个类型,一个函数,两个参数,以及一个数组变量,但都是无法使用的。


你的短语类似的``非结构'''''声明"我发现

莫名其妙。什么是相似的声明你指的是什么?


-

Eric Sosman
es ***** @ ieee-dot-org.inva lid

If "word" were omitted, how would you make use of the
pointer that it names? Let''s omit a few more identifiers:

struct {
char*;
int;
};
int (int, const char*[]) {
struct [] = {
"auto", 0
};
}

What sense can be made of this (invalid) source code? It
declares (sort of) a type, a function, two parameters, and
an array variable, but all are unusable.

Your phrase "similar ``non-struct'''' declarations" I find
baffling. What "similar" declarations do you refer to?

--
Eric Sosman
es*****@ieee-dot-org.invalid


mdh< md ** @ comcast。 netwrote:
mdh <md**@comcast.netwrote:

快速提问。

在下面的代码中,省略单词word,如char * word,

产生语法错误。
Quick question.
In the code below, omitting the word "word", as in char *word,
produces an error of syntax.


在类似的非结构中声明,表达式char *应该

就够了。 ( 我认为)。
In similar "non-struct" declarations, the expression "char *" should
suffice. ( I think).



你对''非结构'是什么意思?声明?一行

只需


char *;


总是语法错误,也在结构声明之外。

What do you mean with ''"non-struct" declarations''? A line with
just

char *;

is always a syntax error, also outside a structure declaration.


是否有人需要添加此内容?

结构是独一无二的。
Is there a reason that one needs to add this? Is
this unique to structs.



如果
没有名字,你会如何访问结构中的''word''成员?只写(只有在initia-

lization期间)结构的成员几乎没有多大意义......

How would you access the ''word'' member of the structure if it
wouldn''t have a name? Write-only (and that only during initia-
lization) members of a structure hardly make much sense...


struct key {

char * word;

int count;

};
struct key {
char *word;
int count;
};


int main(int argc,const char * argv []){
int main (int argc, const char * argv[]) {


struct key keytab [] = {

" auto",0

};

}
struct key keytab[] = {
"auto", 0
};
}



问候,Jens

-

\ Jens Thoms Toerring ___ jt@toerring.de

\ __________________________ http:// toerring .de


8月23日12:10 * pm,Eri​​c Sosman< esos ... @ ieee-dot-org.invalidwrote:
On Aug 23, 12:10*pm, Eric Sosman <esos...@ieee-dot-org.invalidwrote:

mdh写道:
mdh wrote:

快速提问。
Quick question.



* * *如果word被省略了,你怎么会利用它命名的

指针? *让我们省略一些标识符:


* * * * struct {

* * * * * * char *;

* * * * * * int;

* * * *};

* * * * int(int,const char * []){

* * * * * * struct [] = {

* * * * * * * *" auto",0

* * * * * *};

* * * *}


这个(无效的)源代码有什么意义? *它

声明(类型)一个类型,一个函数,两个参数,并且

一个数组变量,但都是无法使用的。


* * *你的短语类似的``非结构''''声明我发现

莫名其妙。 *什么是类似的声明你指的是什么?


* * *If "word" were omitted, how would you make use of the
pointer that it names? *Let''s omit a few more identifiers:

* * * * struct {
* * * * * * char*;
* * * * * * int;
* * * * };
* * * * int (int, const char*[]) {
* * * * * * struct [] = {
* * * * * * * * "auto", 0
* * * * * * };
* * * * }

What sense can be made of this (invalid) source code? *It
declares (sort of) a type, a function, two parameters, and
an array variable, but all are unusable.

* * *Your phrase "similar ``non-struct'''' declarations" I find
baffling. *What "similar" declarations do you refer to?




冒着进一步嘲笑的风险,我认为**这是一个有效的

比较。


void foo(int a,char c){


int b;

char c;


b = a;





}

现在声明,如果我是没错,可能是


void foo(int,char);

显然,这是不同的,但现在确定原因。



At the risk of further ridicule, I **thought** this a valid
comparison.

void foo ( int a, char c){

int b;
char c;

b = a;

etc

}
Now the declaration, if I am not mistaken, could be

void foo ( int, char);
Clearly, this is different, but now sure why.


>
>



这篇关于更多结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆