关于指针类型的简单问题 [英] Simple question about pointer types

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

问题描述

您好,

所有指针类型的长度是否相同?我的直觉告诉我是的,

但我只是想和专家确认一下。所以如果我有


typedef struct {

char * field1;

int field2;

} myStruct;


myStruct * a;

char * b;

int * c;

变量a,b和c是变量a,b和c。所有32位长度?谢谢, -

Dave

Hello,
Are all pointer types the same length? My instinct tells me yes,
but I just wanted to confirm with the experts. So if I have

typedef struct {
char* field1;
int field2;
} myStruct;

myStruct *a;
char *b;
int *c;

Are the variables "a", "b", and "c" all 32 bits in length? Thanks, -
Dave

推荐答案

la *********** @ zipmail.com 写道:
你好,
都是指针类型长度相同?我的直觉告诉我是的,
但我只是想与专家确认一下。所以如果我有

typedef struct {
char * field1;
int field2;
} myStruct;

myStruct * a; < br *> char * b;
int * c;

变量是a,b和c。所有32位长度?谢谢, -





你可以用sizeof(char *)来检查这个。


问候,

Daniel

Dave
Hello,
Are all pointer types the same length? My instinct tells me yes,
but I just wanted to confirm with the experts. So if I have

typedef struct {
char* field1;
int field2;
} myStruct;

myStruct *a;
char *b;
int *c;

Are the variables "a", "b", and "c" all 32 bits in length? Thanks, -
yes

you can check this with sizeof( char* ) and so on.

Regards,
Daniel
Dave



la *********** @ zipmail.com 写道:
你好,
所有指针类型都是相同的长度?


ITYM尺寸

我的直觉告诉我是的,
但我只想与专家确认。所以,如果我有


[snip]

myStruct * a;
char * b;
int * c;
变量a,b和c是变量a,b和c。所有32位长度?谢谢, -
Hello,
Are all pointer types the same length?
ITYM "size"
My instinct tells me yes,
but I just wanted to confirm with the experts. So if I have
[snip]
myStruct *a;
char *b;
int *c; Are the variables "a", "b", and "c" all 32 bits in length? Thanks, -




不,两种情况都没有指定大小。


有四组指针是需要具有相同的表示和对齐(因此大小):指向

1)un / qualified兼容类型; 2)空白和字符类型; 3)

结构类型; 4)联合类型。


所以,举一个例子,理论上

unsigned int * up;

signed int * sp ;

`up''和'sp''可能有不同的尺寸(和其他属性)。


-

Stan Tobias

mailx`echo si***@FamOuS.BedBuG.pAlS.INVA LID | sed s / [[:upper:]] // g`



No, the size is not specified in either case.

There are four groups of pointers that are required to have the
same representation and alignment (hence size, too): pointers to
1) un/qualified compatible types; 2) void and character types; 3)
struct types; 4) union types.

So, for an example, in theory
unsigned int *up;
signed int *sp;
`up'' and `sp'' might have different sizes (and other properties).

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`


Daniel Etzold< de ***** @ gmx.net>写道:
Daniel Etzold <de*****@gmx.net> wrote:
la *********** @ zipmail。 com 写道:
myStruct * a;
char * b;
int * c;

变量a,b和c是变量a,b和c。所有32位长度?谢谢, -
myStruct *a;
char *b;
int *c;

Are the variables "a", "b", and "c" all 32 bits in length? Thanks, -



yes


yes




天哪,不!看到我的其他回复。


-

Stan Tobias

mailx`echo si *** @FamOuS.BedBuG.pAlS.INVA LID | sed s / [[:upper:]] // g`



Goodness, NO! See my other reply.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`


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

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