什么类型是引用数组变量? [英] What type is the reference to an array variable?

查看:219
本文介绍了什么类型是引用数组变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

/*
 * Pointer to a function that reads a codesegment
 */
typedef bool (*BRCS)(void *, uint32, uint64 *, uint64 *, const char **, const char **);
BRCS get_prog_id;

/*
 * 'get_prog_id' is loaded from a dynamic library
 */

uint64 start_o;
uint64 length_o;
char prog_id[256];
char err[256];

get_prog_id(NULL, 0, &start_o, &length_o, &prog_id, &err);

当我跑我的编译器,我得到以下警告:

When I run my compiler, I get the following warnings:

passing argument 5 of get_prog_id from incompatible pointer type    
passing argument 6 of get_prog_id from incompatible pointer type    

因此​​,它的抱怨,我没有的char ** 我的最后两个参数。

我很困惑。我的理解是变量重新presenting 类型的数组相当于一个指针键入。因此,应用&放大器; 运营商会给你一个指针指向一个键入

I'm confused. My understanding was that the variable representing an array of TYPES is equivalent to a pointer to a TYPE. As such, applying the & operator would give you a pointer to a pointer to a TYPE.

我是什么在这里失踪?

推荐答案

有这里有两个问题:

(1)

的类型&放大器; prog_id 不是的char * ,这是字符(* )[256] ;即指针到char型数组的长度256。

The type of &prog_id is not char *, it's char (*)[256]; i.e. pointer-to-char-array-of-length-256.

(2)

即使你可以得到一个的char ** (如的char * prog_id =的malloc(256);&安培; prog_id ),的char ** 是的的有为const char **兼容,为有些模糊的原因。最好的解释,如果可能的位置: http://c-faq.com/ansi/constmismatch.html

Even if you could get a char ** (e.g. char *prog_id = malloc(256); &prog_id), char ** is not compatible with const char **, for somewhat obscure reasons. The best explanation if probably here: http://c-faq.com/ansi/constmismatch.html.

这篇关于什么类型是引用数组变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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