struct枚举类型 [英] struct enumerating types

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

问题描述

我想写一个''struct''。我有一个完全不适合这项任务的图书馆。


所以我正在寻找填补以下空白的C代码:

#undef whateverkeithsaysfor99compliance

#define whateverkeithays for99compliance

int main(void

{

struct foo

printf foo

返回0;

}

/ * end pseudosource * /

我想要一个枚举类型的维度,例如

foo.int = 9;

foo.char =''c'' ;

和另一个带有相应printf说明符的维度,例如

foo.int.format ="%i";

foo.char .format ="%c";


Q1)C99中有多少种类型? LS

I would like to write a ''struct''. I have a library that is all but
completely inappropriate for this task.

So I''m looking for C code that fills in the gaps between:
#undef whateverkeithsaysfor99compliance
#define whateverkeithsays for99compliance
int main(void
{
struct foo

printf foo
return 0;
}
/*end pseudosource */
I would like one dimension enumerating types, e.g.
foo.int = 9;
foo.char = ''c'';
and another dimension with the appropriate printf specifier, e.g.
foo.int.format = "%i";
foo.char.format = "%c";

Q1) How many types exist in C99? LS

推荐答案



" Lane Straatman" < in ***** @ invalid.netwrote in message

news:12 ************* @ corp.supernews.com ...

"Lane Straatman" <in*****@invalid.netwrote in message
news:12*************@corp.supernews.com...

>我想写一个''struct''。我有一个完全不适合这项任务的图书馆。


所以我正在寻找填补以下空白的C代码:

#undef whateverkeithsaysfor99compliance

#define whateverkeithays for99compliance

int main(void

{

struct foo


printf foo

返回0;

}

/ * end pseudosource * /

我想要一个枚举类型的维度,例如

foo.int = 9;

foo.char =''c'';

和另一个带有相应printf说明符的维度,例如

foo.int.format ="%i";

foo.char.format =" ;%c"


Q1)C99中有多少种类型? LS
>I would like to write a ''struct''. I have a library that is all but
completely inappropriate for this task.

So I''m looking for C code that fills in the gaps between:
#undef whateverkeithsaysfor99compliance
#define whateverkeithsays for99compliance
int main(void
{
struct foo

printf foo
return 0;
}
/*end pseudosource */
I would like one dimension enumerating types, e.g.
foo.int = 9;
foo.char = ''c'';
and another dimension with the appropriate printf specifier, e.g.
foo.int.format = "%i";
foo.char.format = "%c";

Q1) How many types exist in C99? LS



Ints的范围从短到长,所以我打赌那里至少有十几个b $ b。 />

#define nothingatall

typedef struct foo(int,char)

int main(void)

{


struct foo

{

int a;

char b;

};


foo.a = 40;

foo.b =''k'';

printf("%i \ n",foo.a);

printf("%c\ n",foo.b);

返回0 ;

}

/ *结束源* /

我无法编译。违规行以''typedef''开头。 LS

Ints range from a short to a long long, so I bet there''s at least a dozen
there.

#define nothingatall
typedef struct foo(int, char)
int main(void)
{

struct foo
{
int a;
char b;
};

foo.a = 40;
foo.b = ''k'';
printf("%i\n", foo.a);
printf("%c\n", foo.b);
return 0;
}
/* end source */
I can''t get this to compile. The offending line begins with ''typedef''. LS


" Lane Straatman" < in ***** @ invalid.netwrites:

[...]
"Lane Straatman" <in*****@invalid.netwrites:
[...]

Q1)C99中有多少种类型? LS
Q1) How many types exist in C99? LS



Ints的范围从短到长,所以我打赌那里至少有十几个b $ b。

Ints range from a short to a long long, so I bet there''s at least a dozen
there.



" int"是单一类型。有许多*整数*类型。


在C99中,至少有:

char,signed char,unsigned char,

short,unsigned short,

int,unsigned int,

long,unsigned long,

long long,unsigned long long

所以'是11,加上任何实现定义的扩展整数类型。


问题是多少种类型。如果你真的意味着类型而不仅仅是整数类型,那么还有void,float,double,long

double,等等。添加指针,结构,联合,枚举和

函数类型,答案就是你要定义的数量。

"int" is a single type. There are a number of *integer* types.

In C99, there are at least:
char, signed char, unsigned char,
short, unsigned short,
int, unsigned int,
long, unsigned long,
long long, unsigned long long
so that''s 11, plus any implementation-defined extended integer types.

The question was "How many types". If you really meant types rather
than just integer types, there''s also void, float, double, long
double, and so forth. Add pointer, struct, union, enumeration, and
function types, and the answer is as many as you care to define.


# define nothingatall
#define nothingatall



你不能使用这个宏。它的目的是什么?

You don''t use this macro. What is its purpose?


typedef struct foo(int,char)
typedef struct foo(int, char)



这不是接近足以使我能够理解它应该是什么样子。你可能只是放弃

那条线;实际上没有必要为struct

类型声明typedef。如果你有一个类型struct foo,你可以称之为struct

foo。

This doesn''t come close enough to making sense for me to be able to
guess what it''s supposed to look like. You could probably just drop
that line; there''s really no need to declare a typedef for a struct
type. If you have a type "struct foo", you can just call it "struct
foo".


int main(void )

{


struct foo

{

int a;

char b;

};


foo.a = 40;

foo.b =''k'' ;
int main(void)
{

struct foo
{
int a;
char b;
};

foo.a = 40;
foo.b = ''k'';



你没有名为foo的对象。你甚至没有一个名为foo的类型


You don''t have an object named "foo". You don''t even have a type
named "foo".


printf("%i \ n", foo.a);

printf("%c\ n",foo.b);
printf("%i\n", foo.a);
printf("%c\n", foo.b);



在没有原型的情况下调用printf()会调用未定义的行为。

获取原型的方法是添加#include< stdio.h>"。

Calling printf() without a prototype invokes undefined behavior.
The way to get a prototype is to add "#include <stdio.h>".


返回0;

}

/ * end source * /

我无法编译。违规行以''typedef''开头。 LS
return 0;
}
/* end source */
I can''t get this to compile. The offending line begins with ''typedef''. LS



这是一个与你所写的类似的正确程序:


#include< stdio .h>

int main(无效)

{

struct foo {

int a;

char b;

};

struct foo foo_obj;


foo_obj.a = 40;

foo_obj.b =''k'';

printf("%i \ n",foo_obj.a);

printf( %c\ n,foo_obj.b);

返回0;

}


不知道你是什么'我想要完成,我不知道

这是否是你正在寻找的。


顺便提一下,你在上一篇文章中写道:

| #undef whateverkeithsaysfor99compliance

| #define whateverkeithsays for99compliance


这是指我吗?这是试图引起我的注意吗?


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http:/ /users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

Here''s a correct program that''s similar to what you wrote:

#include <stdio.h>
int main(void)
{
struct foo {
int a;
char b;
};
struct foo foo_obj;

foo_obj.a = 40;
foo_obj.b = ''k'';
printf("%i\n", foo_obj.a);
printf("%c\n", foo_obj.b);
return 0;
}

Without knowing what you''re trying to accomplish, I have no idea
whether this is what you''re looking for.

Incidentally, in your previous article you wrote:
| #undef whateverkeithsaysfor99compliance
| #define whateverkeithsays for99compliance

Does that refer to me? Was it an attempt to get my attention?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Lane Straatman写道:
Lane Straatman wrote:

" Lane Straatman" < in ***** @ invalid.netwrote in message

news:12 ************* @ corp.supernews.com ...
"Lane Straatman" <in*****@invalid.netwrote in message
news:12*************@corp.supernews.com...

我想写一个''struct''。我有一个库,只有

完全不适合这项任务。
I would like to write a ''struct''. I have a library that is all but
completely inappropriate for this task.



嗯?我不太明白你想说什么?

Huh? I can''t quite understand what you''re trying to say?


所以我在找C代码填补以下空白:

#undef whateverkeithsaysfor99compliance

#define whateverkeithays for99compliance

int main(void

{

struct foo

printf foo

返回0;

}

/ * end pseudosource * /

我想要一个枚举类型的维度,例如

foo.int = 9;

foo.char =''c'';

和另一个具有相应printf说明符的维度,例如

foo.int.format ="%i";

foo.char.format ="%c";
So I''m looking for C code that fills in the gaps between:
#undef whateverkeithsaysfor99compliance
#define whateverkeithsays for99compliance
int main(void
{
struct foo

printf foo
return 0;
}
/*end pseudosource */
I would like one dimension enumerating types, e.g.
foo.int = 9;
foo.char = ''c'';
and another dimension with the appropriate printf specifier, e.g.
foo.int.format = "%i";
foo.char.format = "%c";



你的意思是你想要一些工具来自动生成结构

声明和printf()格式说明符为什么?为什么你想要b $ b b想要那个?

Do you mean you want some tool to automatically generate struct
declarations and printf() format specifiers for them? Why would you
want that?


Q1)C99中有多少种类型? LS
Q1) How many types exist in C99? LS



Ints的范围从短到长,所以我打赌那里至少有十几个b $ b。

Ints range from a short to a long long, so I bet there''s at least a dozen
there.



int是一种特定类型。整数是这类类型的集合

包括char,short,int,long,long long和它们的未签名

等价物。无论是签名还是未签名的纯字符是实现

定义。

int is a specific type. Integers are a collection of such types
including char, short, int, long, long long and their unsigned
equivalents. Whether plain char is signed or unsigned is implementation
defined.


#define nothingatall

typedef struct foo( int,char)
#define nothingatall
typedef struct foo(int, char)



这是什么意思。如果你想键入一个结构类型,请执行以下操作:


typedef struct {

/ * members * /

}名称;


但是我发现处理普通结构类型比它们的

typedef'版本更容易。 YMMV。

What is that supposed to mean. If you want to typedef a struct type do
something like:

typedef struct {
/* members */
} name;

However I find dealing with plain struct types easier than their
typedef''ed versions. YMMV.


int main(void)

{


struct foo

{

int a;

char b;

};


foo .a = 40;

foo.b =''k'';
int main(void)
{

struct foo
{
int a;
char b;
};

foo.a = 40;
foo.b = ''k'';



您不能再分配给类型,而不能分配给int。没有记忆

是为他们分配的。你需要声明一个或多个类型为

foo的对象并为它们赋值。

You can''t assign to types anymore than you can assign to int. No memory
is allocated for them. You need to declare one or more objects of type
foo and assign values to them.


printf("%i \ n" ;,foo.a);

printf("%c\ n",foo.b);

返回0;

}

/ * end source * /

我无法编译。违规行以''typedef''开头。 LS
printf("%i\n", foo.a);
printf("%c\n", foo.b);
return 0;
}
/* end source */
I can''t get this to compile. The offending line begins with ''typedef''. LS



那是因为你是typedef是错误的。使用typedef作为

结构就像我已经显示的那样,或者只使用普通结构。

That''s because, you''re typedef is wrong. Either use typedefs for
structure like I''ve shown or just use plain structs.


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

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